tracker r2577 - in branches/turtle: . src/tracker-indexer
- From: pvanhoof svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2577 - in branches/turtle: . src/tracker-indexer
- Date: Wed, 26 Nov 2008 12:22:38 +0000 (UTC)
Author: pvanhoof
Date: Wed Nov 26 12:22:38 2008
New Revision: 2577
URL: http://svn.gnome.org/viewvc/tracker?rev=2577&view=rev
Log:
2008-11-26 Philip Van Hoof <philip codeminded be>
* src/tracker-indexer/tracker-removable-device.c: Copying with
predicates that we don't know about in our own ontology.
Modified:
branches/turtle/ChangeLog
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:22:38 2008
@@ -62,22 +62,25 @@
typedef struct {
const gchar *ttl_file;
gchar *last_subject;
- TrackerDataMetadata *metadata;
gchar *base;
guint amount;
- TrackerIndexer *indexer;
- gchar *rdf_type;
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;
static void
-foreach_in_metadata (TrackerField *field, gpointer value, gpointer user_data)
+foreach_in_hash (gpointer key, gpointer value, gpointer user_data)
{
raptor_statement *statement;
TurtleParseInfo *item = user_data;
@@ -101,7 +104,7 @@
statement->subject = (void *) raptor_new_uri (about_uri);
statement->subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
- statement->predicate = (void *) raptor_new_uri (tracker_field_get_name (field));
+ statement->predicate = (void *) raptor_new_uri (key);
statement->predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
statement->object = (unsigned char *) g_strdup (value);
@@ -121,9 +124,9 @@
optimizer (const gchar *subject, const gchar *rdf_type, TurtleParseInfo *info)
{
info->about_uri = (gchar *) subject;
- tracker_data_metadata_foreach (info->metadata,
- foreach_in_metadata,
- info);
+ g_hash_table_foreach (info->hash,
+ foreach_in_hash,
+ info);
}
static void
@@ -148,11 +151,16 @@
info->amount++;
- tracker_data_metadata_free (info->metadata);
+ if (info->metadata)
+ tracker_data_metadata_free (info->metadata);
+ if (info->hash)
+ g_hash_table_destroy (info->hash);
+
g_free (info->last_subject);
g_free (info->rdf_type);
info->last_subject = NULL;
info->metadata = NULL;
+ info->hash = NULL;
info->rdf_type = NULL;
}
@@ -223,6 +231,63 @@
}
+
+
+static void
+consume_triple_optimizer (void* user_data, const raptor_statement* triple)
+{
+ TurtleParseInfo *info = user_data;
+ gchar *subject;
+
+ subject = (gchar *) raptor_uri_as_string ((raptor_uri *) triple->subject);
+
+ if (!info->last_subject || strcmp (subject, info->last_subject) != 0) {
+
+ /* Commit previous subject */
+
+ commit_turtle_parse_info_data (info, TRUE, info->exec_func);
+ info->last_subject = g_strdup (subject);
+ info->hash = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+ }
+
+ if (triple->object_type == RAPTOR_IDENTIFIER_TYPE_LITERAL) {
+ gchar *predicate;
+
+ predicate = g_strdup ((const gchar *) raptor_uri_as_string ((raptor_uri *) triple->predicate));
+
+ if (strcmp (predicate, "rdf:type") == 0) {
+ g_free (info->rdf_type);
+
+ /* TODO: ontology */
+ /* Change this when Files and Emails becomes File and Email */
+
+ info->rdf_type = g_strdup_printf ("%ss", triple->object);
+ } else
+ g_hash_table_replace (info->hash,
+ predicate,
+ g_strdup (triple->object));
+
+ } else if (triple->object_type == RAPTOR_IDENTIFIER_TYPE_RESOURCE) {
+ gchar *key = g_strdup_printf ("file://%s/:", info->base);
+
+ if (strcmp (key, triple->object) == 0) {
+ gchar *predicate;
+
+ predicate = (gchar *) raptor_uri_as_string ((raptor_uri *) triple->predicate);
+
+ g_hash_table_replace (info->hash,
+ predicate,
+ g_strdup (triple->object));
+
+ }
+
+ g_free (key);
+ }
+
+}
+
static void
raptor_error (void *user_data, raptor_locator* locator, const char *message)
{
@@ -284,7 +349,7 @@
info->exec_func = (executer_func) optimizer;
info->transactions = FALSE;
- raptor_set_statement_handler (parser, info, consume_triple);
+ 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);
@@ -292,13 +357,8 @@
copy_file = g_strdup (file);
ptr = strstr (copy_file, "/metadata/metadata.ttl");
- if (ptr) {
- /* .cache remains, and will be cut later, just like dummy_file is */
- *ptr = '\0';
- } else {
- g_free (copy_file);
- copy_file = g_strdup ("/home/pvanhoof/dummy_file");
- }
+ /* .cache remains, and will be cut later, just like dummy_file is */
+ *ptr = '\0';
uri_stringa = raptor_uri_filename_to_uri_string (file);
uri_stringb = raptor_uri_filename_to_uri_string (copy_file);
@@ -387,14 +447,8 @@
copy_file = g_strdup (file);
ptr = strstr (copy_file, "/metadata/metadata.ttl");
- if (ptr) {
- /* .cache remains, and will be cut later, just like dummy_file is */
- *ptr = '\0';
- } else {
- g_free (copy_file);
- copy_file = g_strdup ("/home/pvanhoof/dummy_file");
- }
-
+ /* .cache remains, and will be cut later, just like dummy_file is */
+ *ptr = '\0';
uri_stringa = raptor_uri_filename_to_uri_string (file);
uri_stringb = raptor_uri_filename_to_uri_string (copy_file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]