tracker r2579 - branches/turtle/src/tracker-indexer
- From: pvanhoof svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2579 - branches/turtle/src/tracker-indexer
- Date: Wed, 26 Nov 2008 12:44:27 +0000 (UTC)
Author: pvanhoof
Date: Wed Nov 26 12:44:26 2008
New Revision: 2579
URL: http://svn.gnome.org/viewvc/tracker?rev=2579&view=rev
Log:
Cleaning up
Modified:
branches/turtle/src/tracker-indexer/tracker-removable-device.c
Modified: branches/turtle/src/tracker-indexer/tracker-removable-device.c
==============================================================================
--- branches/turtle/src/tracker-indexer/tracker-removable-device.c (original)
+++ branches/turtle/src/tracker-indexer/tracker-removable-device.c Wed Nov 26 12:44:26 2008
@@ -54,38 +54,34 @@
#include <libtracker-data/tracker-data-query.h>
#include <libtracker-data/tracker-data-update.h>
-
-typedef void (*executer_func) (const gchar *subject,
- const gchar *rdf_type,
- gpointer info);
-
typedef struct {
const gchar *ttl_file;
gchar *last_subject;
gchar *base;
guint amount;
- executer_func exec_func;
- gboolean transactions;
-
- /* These are only used by the optimizer */
- raptor_serializer *serializer;
- gchar *uri, *about_uri;
- GHashTable *hash;
-
- /* These are only used by the in-data handler */
TrackerIndexer *indexer;
TrackerDataMetadata *metadata;
gchar *rdf_type;
-} TurtleParseInfo;
+} TurtleStorerInfo;
+typedef struct {
+ const gchar *ttl_file;
+ gchar *last_subject;
+ gchar *base;
+ guint amount;
+ gchar *rdf_type;
+ raptor_serializer *serializer;
+ gchar *uri, *about_uri;
+ GHashTable *hash;
+} TurtleOptimizerInfo;
static void
foreach_in_hash (gpointer key, gpointer value, gpointer user_data)
{
- raptor_statement *statement;
- TurtleParseInfo *item = user_data;
- const gchar *about_uri = item->uri;
- raptor_serializer *serializer = item->serializer;
+ raptor_statement *statement;
+ TurtleOptimizerInfo *item = user_data;
+ const gchar *about_uri = item->last_subject;
+ raptor_serializer *serializer = item->serializer;
/* TODO: cope with group values by making them ; separated, perhaps by
* reading the type from the TrackerField? Also, numeric values don't
@@ -120,47 +116,48 @@
g_free (statement);
}
-static void
-optimizer (const gchar *subject, const gchar *rdf_type, TurtleParseInfo *info)
-{
- info->about_uri = (gchar *) subject;
- g_hash_table_foreach (info->hash,
- foreach_in_hash,
- info);
-}
static void
-put_in_tracker_data (const gchar *subject, const gchar *rdf_type, TurtleParseInfo *info)
+commit_turtle_parse_info_optimizer (TurtleOptimizerInfo *info)
{
- /* We have it as a URI, database api wants Paths. Update this when
- * the database api becomes sane and uses URIs everywhere */
+ if (info->last_subject) {
- tracker_data_replace_service (subject + 7,
- rdf_type,
- info->metadata);
+ g_hash_table_foreach (info->hash,
+ foreach_in_hash,
+ info);
+
+ info->amount++;
+
+ g_hash_table_destroy (info->hash);
+
+ g_free (info->last_subject);
+ g_free (info->rdf_type);
+ info->last_subject = NULL;
+ info->hash = NULL;
+ info->rdf_type = NULL;
+ }
}
static void
-commit_turtle_parse_info_data (TurtleParseInfo *info, gboolean may_flush, executer_func exec_func)
+commit_turtle_parse_info_storer (TurtleStorerInfo *info, gboolean may_flush)
{
if (info->last_subject) {
- exec_func (info->last_subject,
- info->rdf_type,
- info);
+ /* We have it as a URI, database api wants Paths. Update this when
+ * the database api becomes sane and uses URIs everywhere */
+
+ tracker_data_replace_service (info->last_subject + 7,
+ info->rdf_type,
+ info->metadata);
info->amount++;
- if (info->metadata)
- tracker_data_metadata_free (info->metadata);
- if (info->hash)
- g_hash_table_destroy (info->hash);
+ tracker_data_metadata_free (info->metadata);
g_free (info->last_subject);
g_free (info->rdf_type);
info->last_subject = NULL;
info->metadata = NULL;
- info->hash = NULL;
info->rdf_type = NULL;
}
@@ -169,20 +166,20 @@
* moment */
if (may_flush && info->amount > 100) {
- if (info->transactions)
- tracker_indexer_commit_transaction (info->indexer);
+ tracker_indexer_commit_transaction (info->indexer);
g_main_context_iteration (NULL, FALSE);
- if (info->transactions)
- tracker_indexer_open_transaction (info->indexer);
+ tracker_indexer_open_transaction (info->indexer);
info->amount = 0;
}
}
+
+
static void
-consume_triple (void* user_data, const raptor_statement* triple)
+consume_triple_storer (void* user_data, const raptor_statement* triple)
{
- TurtleParseInfo *info = user_data;
- gchar *subject;
+ TurtleStorerInfo *info = user_data;
+ gchar *subject;
subject = (gchar *) raptor_uri_as_string ((raptor_uri *) triple->subject);
@@ -190,7 +187,7 @@
/* Commit previous subject */
- commit_turtle_parse_info_data (info, TRUE, info->exec_func);
+ commit_turtle_parse_info_storer (info, TRUE);
info->last_subject = g_strdup (subject);
info->metadata = tracker_data_metadata_new ();
}
@@ -232,12 +229,11 @@
}
-
static void
consume_triple_optimizer (void* user_data, const raptor_statement* triple)
{
- TurtleParseInfo *info = user_data;
- gchar *subject;
+ TurtleOptimizerInfo *info = user_data;
+ gchar *subject;
subject = (gchar *) raptor_uri_as_string ((raptor_uri *) triple->subject);
@@ -245,7 +241,7 @@
/* Commit previous subject */
- commit_turtle_parse_info_data (info, TRUE, info->exec_func);
+ commit_turtle_parse_info_optimizer (info);
info->last_subject = g_strdup (subject);
info->hash = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
@@ -291,8 +287,9 @@
static void
raptor_error (void *user_data, raptor_locator* locator, const char *message)
{
- TurtleParseInfo *info = user_data;
- g_message ("RAPTOR parse error: %s for %s\n", message, info->ttl_file);
+ g_message ("RAPTOR parse error: %s for %s\n",
+ message,
+ (gchar *) user_data);
}
@@ -308,14 +305,14 @@
"metadata", "metadata.ttl", NULL);
if (g_file_test (file, G_FILE_TEST_EXISTS)) {
- unsigned char *uri_stringa, *uri_stringb;
- raptor_uri *uri, *base_uri, *suri;
- static gboolean has_init = FALSE;
- raptor_parser *parser;
- TurtleParseInfo *info;
- gchar *copy_file,
- *ptr, *tmp_file;
- FILE *target_file;
+ unsigned char *uri_stringa, *uri_stringb;
+ raptor_uri *uri, *base_uri, *suri;
+ static gboolean has_init = FALSE;
+ raptor_parser *parser;
+ TurtleOptimizerInfo *info;
+ gchar *copy_file,
+ *ptr, *tmp_file;
+ FILE *target_file;
tmp_file = g_strdup_printf ("%s.tmp", file);
@@ -334,7 +331,7 @@
parser = raptor_new_parser ("turtle");
- info = g_slice_new0 (TurtleParseInfo);
+ info = g_slice_new0 (TurtleOptimizerInfo);
info->serializer = raptor_new_serializer ("turtle");
suri = raptor_new_uri ("/");
@@ -342,17 +339,12 @@
suri, target_file);
info->ttl_file = file;
- info->indexer = g_object_ref (indexer);
info->amount = 0;
- /* The optimizer simply writes all triples to the serializer */
- info->exec_func = (executer_func) optimizer;
- info->transactions = FALSE;
-
raptor_set_statement_handler (parser, info, consume_triple_optimizer);
- raptor_set_fatal_error_handler (parser, info, raptor_error);
- raptor_set_error_handler (parser, info, raptor_error);
- raptor_set_warning_handler (parser, info, raptor_error);
+ raptor_set_fatal_error_handler (parser, file, raptor_error);
+ raptor_set_error_handler (parser, file, raptor_error);
+ raptor_set_warning_handler (parser, file, raptor_error);
copy_file = g_strdup (file);
@@ -376,15 +368,14 @@
raptor_parse_file (parser, uri, base_uri);
/* Commit final subject (or loop doesn't handle the very last) */
- commit_turtle_parse_info_data (info, FALSE, info->exec_func);
+ commit_turtle_parse_info_optimizer (info);
raptor_serialize_end (info->serializer);
raptor_free_serializer(info->serializer);
fclose (target_file);
g_free (copy_file);
- g_object_unref (info->indexer);
- g_slice_free (TurtleParseInfo, info);
+ g_slice_free (TurtleOptimizerInfo, info);
raptor_free_parser (parser);
@@ -418,31 +409,27 @@
"metadata", "metadata.ttl", NULL);
if (g_file_test (file, G_FILE_TEST_EXISTS)) {
- unsigned char *uri_stringa, *uri_stringb;
- raptor_uri *uri, *base_uri;
- static gboolean has_init = FALSE;
- raptor_parser *parser;
- TurtleParseInfo *info;
- gchar *copy_file, *ptr;
+ unsigned char *uri_stringa, *uri_stringb;
+ raptor_uri *uri, *base_uri;
+ static gboolean has_init = FALSE;
+ raptor_parser *parser;
+ TurtleStorerInfo *info;
+ gchar *copy_file, *ptr;
raptor_init();
parser = raptor_new_parser ("turtle");
- info = g_slice_new0 (TurtleParseInfo);
+ info = g_slice_new0 (TurtleStorerInfo);
info->ttl_file = file;
info->indexer = g_object_ref (indexer);
info->amount = 0;
- /* This handler puts the triples into our store */
- info->exec_func = (executer_func) put_in_tracker_data;
- info->transactions = TRUE;
-
- raptor_set_statement_handler (parser, info, consume_triple);
- raptor_set_fatal_error_handler (parser, info, raptor_error);
- raptor_set_error_handler (parser, info, raptor_error);
- raptor_set_warning_handler (parser, info, raptor_error);
+ raptor_set_statement_handler (parser, info, consume_triple_storer);
+ raptor_set_fatal_error_handler (parser, file, raptor_error);
+ raptor_set_error_handler (parser, file, raptor_error);
+ raptor_set_warning_handler (parser, file, raptor_error);
copy_file = g_strdup (file);
@@ -474,7 +461,7 @@
raptor_parse_file (parser, uri, base_uri);
/* Commit final subject (or loop doesn't handle the very last) */
- commit_turtle_parse_info_data (info, FALSE, info->exec_func);
+ commit_turtle_parse_info_storer (info, FALSE);
/* g_timer_stop (timer);
g_print ("\nTIME: %f\n", g_timer_elapsed (timer, NULL)); */
@@ -486,7 +473,7 @@
g_free (copy_file);
g_object_unref (info->indexer);
- g_slice_free (TurtleParseInfo, info);
+ g_slice_free (TurtleStorerInfo, info);
raptor_free_parser (parser);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]