[tracker/slo-onto: 5/12] tracker-writeback: SLO ontology porting



commit e6a97acb76cb829e95887909a7bfa087edce346f
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Jan 10 16:00:52 2011 +0100

    tracker-writeback: SLO ontology porting

 src/libtracker-common/tracker-ontologies.h    |    1 +
 src/tracker-writeback/tracker-writeback-xmp.c |  139 +++++++++++-------------
 2 files changed, 65 insertions(+), 75 deletions(-)
---
diff --git a/src/libtracker-common/tracker-ontologies.h b/src/libtracker-common/tracker-ontologies.h
index 4eccafb..295e113 100644
--- a/src/libtracker-common/tracker-ontologies.h
+++ b/src/libtracker-common/tracker-ontologies.h
@@ -45,6 +45,7 @@ G_BEGIN_DECLS
 #define TRACKER_NFO_PREFIX      "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#";
 
 /* Temporary */
+#define TRACKER_SLO_PREFIX      "http://www.tracker-project.org/temp/slo#";
 #define TRACKER_NMM_PREFIX      "http://www.tracker-project.org/temp/nmm#";
 #define TRACKER_MLO_PREFIX      "http://www.tracker-project.org/temp/mlo#";
 
diff --git a/src/tracker-writeback/tracker-writeback-xmp.c b/src/tracker-writeback/tracker-writeback-xmp.c
index 31b7786..a23866e 100644
--- a/src/tracker-writeback/tracker-writeback-xmp.c
+++ b/src/tracker-writeback/tracker-writeback-xmp.c
@@ -118,6 +118,7 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile    *wbf,
 	XmpStringPtr str;
 #endif
 	GString *keywords = NULL;
+	const gchar *urn = NULL;
 
 	path = g_file_get_path (file);
 
@@ -145,6 +146,8 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile    *wbf,
 	for (n = 0; n < values->len; n++) {
 		const GStrv row = g_ptr_array_index (values, n);
 
+		urn = row[1]; /* The urn is at 1 */
+
 		if (g_strcmp0 (row[2], TRACKER_NIE_PREFIX "title") == 0) {
 			xmp_delete_property (xmp, NS_EXIF, "Title");
 			xmp_set_property (xmp, NS_EXIF, "Title", row[3], 0);
@@ -383,89 +386,75 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile    *wbf,
 			g_free (work_on);
 		}
 #endif /* SET_TYPICAL_CAMERA_FIELDS */
+	}
 
-		if (g_strcmp0 (row[2], TRACKER_MLO_PREFIX "location") == 0 ||
-		    g_strcmp0 (row[2], TRACKER_MLO_PREFIX "city") == 0     ||
-		    g_strcmp0 (row[2], TRACKER_MLO_PREFIX "country") == 0  ||
-		    g_strcmp0 (row[2], TRACKER_MLO_PREFIX "state") == 0    ||
-		    g_strcmp0 (row[2], TRACKER_MLO_PREFIX "address") == 0)
-		{
-			TrackerSparqlCursor *cursor;
-			GError *error = NULL;
-			gchar *query;
-
-			query = g_strdup_printf ("SELECT "
-			                         "tracker:coalesce (mlo:city (?location), nco:locality (mlo:asPostalAddress (?location)))  "
-			                         "tracker:coalesce (mlo:state (?location), nco:region (mlo:asPostalAddress (?location)))  "
-			                         "tracker:coalesce (mlo:address (?location), nco:streetAddress (mlo:asPostalAddress (?location)))  "
-			                         "tracker:coalesce (mlo:country (?location), nco:country (mlo:asPostalAddress (?location)))  "
-			                         "WHERE { <%s> mlo:location ?location }",
-			                         row[1]); /* The urn is at 1 */
-
-			cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
-			g_free (query);
-			if (!error) {
-				if (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
-					const gchar *city, *subl, *country, *state;
-
-					city = tracker_sparql_cursor_get_string (cursor, 0, NULL);
-					state = tracker_sparql_cursor_get_string (cursor, 1, NULL);
-					subl = tracker_sparql_cursor_get_string (cursor, 2, NULL);
-					country = tracker_sparql_cursor_get_string (cursor, 3, NULL);
-
-					/* TODO: A lot of these location fields are pretty vague and ambigious.
-					 * We should go through them one by one and ensure that all of them are
-					 * used sanely */
-
-					if (!tracker_is_blank_string (city)) {
-						xmp_delete_property (xmp, NS_IPTC4XMP, "City");
-						xmp_set_property (xmp, NS_IPTC4XMP, "City", city, 0);
-						xmp_delete_property (xmp, NS_PHOTOSHOP, "City");
-						xmp_set_property (xmp, NS_PHOTOSHOP, "City", city, 0);
-					}
+	if (urn != NULL) {
+		TrackerSparqlCursor *cursor;
+		GError *error = NULL;
+		gchar *query;
+
+		query = g_strdup_printf ("SELECT "
+		                         "nco:locality (?addr) "
+		                         "nco:region (?addr) "
+		                         "nco:streetAddress (?addr) "
+		                         "nco:country (?addr) "
+		                         "WHERE { <%s> slo:location ?loc . "
+		                                 "?loc slo:postalAddress ?addr . }",
+		                         urn);
+
+		cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
+		g_free (query);
+		if (!error) {
+			if (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+				const gchar *city, *subl, *country, *state;
+
+				city = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+				state = tracker_sparql_cursor_get_string (cursor, 1, NULL);
+				subl = tracker_sparql_cursor_get_string (cursor, 2, NULL);
+				country = tracker_sparql_cursor_get_string (cursor, 3, NULL);
+
+				/* TODO: A lot of these location fields are pretty vague and ambigious.
+				 * We should go through them one by one and ensure that all of them are
+				 * used sanely */
+
+				if (!tracker_is_blank_string (city)) {
+					xmp_delete_property (xmp, NS_IPTC4XMP, "City");
+					xmp_set_property (xmp, NS_IPTC4XMP, "City", city, 0);
+					xmp_delete_property (xmp, NS_PHOTOSHOP, "City");
+					xmp_set_property (xmp, NS_PHOTOSHOP, "City", city, 0);
+				}
 
-					if (!tracker_is_blank_string (state)) {
-						xmp_delete_property (xmp, NS_IPTC4XMP, "State");
-						xmp_set_property (xmp, NS_IPTC4XMP, "State", state, 0);
-						xmp_delete_property (xmp, NS_IPTC4XMP, "Province");
-						xmp_set_property (xmp, NS_IPTC4XMP, "Province", state, 0);
-						xmp_delete_property (xmp, NS_PHOTOSHOP, "State");
-						xmp_set_property (xmp, NS_PHOTOSHOP, "State", state, 0);
-					}
+				if (!tracker_is_blank_string (state)) {
+					xmp_delete_property (xmp, NS_IPTC4XMP, "State");
+					xmp_set_property (xmp, NS_IPTC4XMP, "State", state, 0);
+					xmp_delete_property (xmp, NS_IPTC4XMP, "Province");
+					xmp_set_property (xmp, NS_IPTC4XMP, "Province", state, 0);
+					xmp_delete_property (xmp, NS_PHOTOSHOP, "State");
+					xmp_set_property (xmp, NS_PHOTOSHOP, "State", state, 0);
+				}
 
-					if (!tracker_is_blank_string (subl)) {
-						xmp_delete_property (xmp, NS_IPTC4XMP, "SubLocation");
-						xmp_set_property (xmp, NS_IPTC4XMP, "SubLocation", subl, 0);
-						xmp_delete_property (xmp, NS_PHOTOSHOP, "Location");
-						xmp_set_property (xmp, NS_PHOTOSHOP, "Location", subl, 0);
-					}
+				if (!tracker_is_blank_string (subl)) {
+					xmp_delete_property (xmp, NS_IPTC4XMP, "SubLocation");
+					xmp_set_property (xmp, NS_IPTC4XMP, "SubLocation", subl, 0);
+					xmp_delete_property (xmp, NS_PHOTOSHOP, "Location");
+					xmp_set_property (xmp, NS_PHOTOSHOP, "Location", subl, 0);
+				}
 
-					if (!tracker_is_blank_string (country)) {
-						xmp_delete_property (xmp, NS_PHOTOSHOP, "Country");
-						xmp_set_property (xmp, NS_PHOTOSHOP, "Country", country, 0);
-						xmp_delete_property (xmp, NS_IPTC4XMP, "Country");
-						xmp_set_property (xmp, NS_IPTC4XMP, "Country", country, 0);
-						xmp_delete_property (xmp, NS_IPTC4XMP, "PrimaryLocationName");
-						xmp_set_property (xmp, NS_IPTC4XMP, "PrimaryLocationName", country, 0);
-						xmp_delete_property (xmp, NS_IPTC4XMP, "CountryName");
-						xmp_set_property (xmp, NS_IPTC4XMP, "CountryName", country, 0);
-					}
+				if (!tracker_is_blank_string (country)) {
+					xmp_delete_property (xmp, NS_PHOTOSHOP, "Country");
+					xmp_set_property (xmp, NS_PHOTOSHOP, "Country", country, 0);
+					xmp_delete_property (xmp, NS_IPTC4XMP, "Country");
+					xmp_set_property (xmp, NS_IPTC4XMP, "Country", country, 0);
+					xmp_delete_property (xmp, NS_IPTC4XMP, "PrimaryLocationName");
+					xmp_set_property (xmp, NS_IPTC4XMP, "PrimaryLocationName", country, 0);
+					xmp_delete_property (xmp, NS_IPTC4XMP, "CountryName");
+					xmp_set_property (xmp, NS_IPTC4XMP, "CountryName", country, 0);
 				}
 			}
-
-			g_object_unref (cursor);
-			g_clear_error (&error);
 		}
 
-		/* TODO: When a photo contains a known face
-		 *
-		 * if (g_strcmp0 (row[2], PHOTO_HAS "contact") == 0) {
-		  xmp_delete_property (xmp, FACE, "contact");
-		  Fetch full name of the contact?
-		  xmp_set_array_item (xmp, FACE, "contact", 1, fetched, 0);
-		  }
-		*/
-
+		g_object_unref (cursor);
+		g_clear_error (&error);
 	}
 
 	if (keywords) {



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