[tracker] Split tracker_data_insert_statement



commit c2ac7d2bc1dc9959d6270e966e6e3be833d99615
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Jul 15 15:39:53 2009 +0200

    Split tracker_data_insert_statement
    
    Split tracker_data_insert_statement into insert_statement_with_uri
    and insert_statement_with_string. This fixes string objects that have
    a ':' character upfront (for example strings that start with a smiley).

 src/libtracker-data/libtracker-data.vapi   |    2 +
 src/libtracker-data/tracker-data-manager.c |   15 +++-
 src/libtracker-data/tracker-data-update.c  |  129 +++++++++++++++++++---------
 src/libtracker-data/tracker-data-update.h  |    6 ++
 src/libtracker-data/tracker-turtle.c       |    8 ++
 src/libtracker-data/tracker-turtle.h       |    1 +
 src/tracker-store/tracker-store.c          |   15 +++-
 7 files changed, 127 insertions(+), 49 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 5833400..0bf06e2 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -25,6 +25,8 @@ namespace Tracker {
 		public void commit_transaction ();
 		public void delete_statement (string subject, string predicate, string object);
 		public void insert_statement (string subject, string predicate, string object);
+		public void insert_statement_with_uri (string subject, string predicate, string object);
+		public void insert_statement_with_string (string subject, string predicate, string object);
 		public void delete_resource_description (string uri);
 	}
 }
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 89089e0..b11feec 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -282,10 +282,17 @@ import_ontology_file_from_path (const gchar	 *ontology_file)
 {
 	tracker_turtle_reader_init (ontology_file, NULL);
 	while (tracker_turtle_reader_next ()) {
-		tracker_data_insert_statement (
-			tracker_turtle_reader_get_subject (),
-			tracker_turtle_reader_get_predicate (),
-			tracker_turtle_reader_get_object ());
+		if (tracker_turtle_reader_object_is_uri ()) {
+			tracker_data_insert_statement_with_uri (
+				tracker_turtle_reader_get_subject (),
+				tracker_turtle_reader_get_predicate (),
+				tracker_turtle_reader_get_object ());
+		} else {
+			tracker_data_insert_statement_with_string (
+				tracker_turtle_reader_get_subject (),
+				tracker_turtle_reader_get_predicate (),
+				tracker_turtle_reader_get_object ());
+		}
 	}
 }
 
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index e005a36..592b361 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -842,51 +842,14 @@ tracker_data_delete_statement (const gchar            *subject,
 	tracker_data_commit_transaction ();
 }
 
-void
-tracker_data_insert_statement (const gchar            *subject,
-			       const gchar            *predicate,
-			       const gchar            *object)
+static void
+tracker_data_insert_statement_common (const gchar            *subject,
+				      const gchar            *predicate,
+				      const gchar            *object)
 {
 	TrackerClass       *service;
 	TrackerProperty       *field;
 
-	g_return_if_fail (subject != NULL);
-	g_return_if_fail (predicate != NULL);
-	g_return_if_fail (object != NULL);
-
-	tracker_data_begin_transaction ();
-
-	/* subjects and objects starting with `:' are anonymous blank nodes */
-	if (g_str_has_prefix (object, ":")) {
-		/* anonymous blank node used as object in a statement */
-		const gchar *blank_uri;
-
-		if (blank_buffer.subject != NULL) {
-			if (strcmp (blank_buffer.subject, object) == 0) {
-				/* object still in blank buffer, need to flush buffer */
-				tracker_data_blank_buffer_flush ();
-			}
-		}
-
-		blank_uri = g_hash_table_lookup (blank_buffer.table, object);
-
-		if (blank_uri != NULL) {
-			/* now insert statement referring to blank node */
-			tracker_data_insert_statement (subject, predicate, blank_uri);
-
-			g_hash_table_remove (blank_buffer.table, object);
-
-			tracker_data_commit_transaction ();
-
-			return;
-		} else {
-			/* TODO: to fix this properly, we need to split
-			   tracker_data_insert_statement into two functions,
-			   one for uri objects and one for literal objects */
-			g_warning ("Blank node '%s' not found", object);
-		}
-	}
-
 	if (g_str_has_prefix (subject, ":")) {
 		/* blank node definition
 		   pile up statements until the end of the blank node */
@@ -968,6 +931,90 @@ tracker_data_insert_statement (const gchar            *subject,
 	if (insert_callback) {
 		insert_callback (subject, predicate, object, update_buffer.types, insert_data);
 	}
+}
+
+void
+tracker_data_insert_statement (const gchar            *subject,
+			       const gchar            *predicate,
+			       const gchar            *object)
+{
+	TrackerProperty *property;
+
+	g_return_if_fail (subject != NULL);
+	g_return_if_fail (predicate != NULL);
+	g_return_if_fail (object != NULL);
+
+	property = tracker_ontology_get_property_by_uri (predicate);
+	if (property != NULL) {
+		if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE) {
+			tracker_data_insert_statement_with_uri (subject, predicate, object);
+		} else {
+			tracker_data_insert_statement_with_string (subject, predicate, object);
+		}
+	} else {
+		g_warning ("Property '%s' not found in the ontology", predicate);
+	}
+}
+
+void
+tracker_data_insert_statement_with_uri (const gchar            *subject,
+					const gchar            *predicate,
+					const gchar            *object)
+{
+	g_return_if_fail (subject != NULL);
+	g_return_if_fail (predicate != NULL);
+	g_return_if_fail (object != NULL);
+
+	tracker_data_begin_transaction ();
+
+	/* subjects and objects starting with `:' are anonymous blank nodes */
+	if (g_str_has_prefix (object, ":")) {
+		/* anonymous blank node used as object in a statement */
+		const gchar *blank_uri;
+
+		if (blank_buffer.subject != NULL) {
+			if (strcmp (blank_buffer.subject, object) == 0) {
+				/* object still in blank buffer, need to flush buffer */
+				tracker_data_blank_buffer_flush ();
+			}
+		}
+
+		blank_uri = g_hash_table_lookup (blank_buffer.table, object);
+
+		if (blank_uri != NULL) {
+			/* now insert statement referring to blank node */
+			tracker_data_insert_statement (subject, predicate, blank_uri);
+
+			g_hash_table_remove (blank_buffer.table, object);
+
+			tracker_data_commit_transaction ();
+
+			return;
+		} else {
+			/* TODO: to fix this properly, we need to split
+			   tracker_data_insert_statement into two functions,
+			   one for uri objects and one for literal objects */
+			g_warning ("Blank node '%s' not found", object);
+		}
+	}
+
+	tracker_data_insert_statement_common (subject, predicate, object);
+
+	tracker_data_commit_transaction ();
+}
+
+void
+tracker_data_insert_statement_with_string (const gchar            *subject,
+					   const gchar            *predicate,
+					   const gchar            *object)
+{
+	g_return_if_fail (subject != NULL);
+	g_return_if_fail (predicate != NULL);
+	g_return_if_fail (object != NULL);
+
+	tracker_data_begin_transaction ();
+
+	tracker_data_insert_statement_common (subject, predicate, object);
 
 	tracker_data_commit_transaction ();
 }
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index 1c32acc..5a28354 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -44,6 +44,12 @@ void     tracker_data_delete_statement			(const gchar	     *subject,
 void     tracker_data_insert_statement			(const gchar	     *subject,
 							 const gchar         *predicate,
 							 const gchar         *object);
+void     tracker_data_insert_statement_with_uri		(const gchar	     *subject,
+							 const gchar         *predicate,
+							 const gchar         *object);
+void     tracker_data_insert_statement_with_string	(const gchar	     *subject,
+							 const gchar         *predicate,
+							 const gchar         *object);
 void     tracker_data_begin_transaction			(void);
 void     tracker_data_commit_transaction		(void);
 
diff --git a/src/libtracker-data/tracker-turtle.c b/src/libtracker-data/tracker-turtle.c
index e14b3d1..d72c5f9 100644
--- a/src/libtracker-data/tracker-turtle.c
+++ b/src/libtracker-data/tracker-turtle.c
@@ -41,6 +41,8 @@ static gboolean turtle_first;
 static gchar * volatile turtle_subject;
 static gchar * volatile turtle_predicate;
 static char * volatile turtle_object;
+static raptor_identifier_type volatile turtle_object_type;
+
 static volatile gboolean     turtle_eof;
 
 typedef struct {
@@ -328,6 +330,7 @@ turtle_statement_handler (void                   *user_data,
 	turtle_subject = g_strdup ((const gchar *) raptor_uri_as_string ((raptor_uri *) triple->subject));
 	turtle_predicate = g_strdup ((const gchar *) raptor_uri_as_string ((raptor_uri *) triple->predicate));
 	turtle_object = g_strdup ((const gchar *) triple->object);
+	turtle_object_type = triple->object_type;
 
 	/* signal main thread to pull statement */
 	g_cond_signal (turtle_cond);
@@ -590,3 +593,8 @@ tracker_turtle_reader_get_object (void)
 	return turtle_object;
 }
 
+gboolean
+tracker_turtle_reader_object_is_uri (void)
+{
+	return (turtle_object_type == RAPTOR_IDENTIFIER_TYPE_RESOURCE);
+}
diff --git a/src/libtracker-data/tracker-turtle.h b/src/libtracker-data/tracker-turtle.h
index 1675f3e..d7ced93 100644
--- a/src/libtracker-data/tracker-turtle.h
+++ b/src/libtracker-data/tracker-turtle.h
@@ -59,6 +59,7 @@ gboolean     tracker_turtle_reader_next          (void);
 const gchar *tracker_turtle_reader_get_subject   (void);
 const gchar *tracker_turtle_reader_get_predicate (void);
 const gchar *tracker_turtle_reader_get_object    (void);
+gboolean     tracker_turtle_reader_object_is_uri (void);
 
 /* Optimizer, reparser */
 void        tracker_turtle_optimize      (const gchar          *turtle_file);
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index 2e8d13d..c6dc33e 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -97,10 +97,17 @@ process_turtle_file_part (void)
 
 	while (tracker_turtle_reader_next ()) {
 		/* insert statement */
-		tracker_data_insert_statement (
-			tracker_turtle_reader_get_subject (),
-			tracker_turtle_reader_get_predicate (),
-			tracker_turtle_reader_get_object ());
+		if (tracker_turtle_reader_object_is_uri ()) {
+			tracker_data_insert_statement_with_uri (
+				tracker_turtle_reader_get_subject (),
+				tracker_turtle_reader_get_predicate (),
+				tracker_turtle_reader_get_object ());
+		} else {
+			tracker_data_insert_statement_with_string (
+				tracker_turtle_reader_get_subject (),
+				tracker_turtle_reader_get_predicate (),
+				tracker_turtle_reader_get_object ());
+		}
 
 		i++;
 		if (i >= 10) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]