[tracker] Location writeback support for XMP formats



commit 44479a3de5b3c163482d49f15a2199b8742eea8d
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Dec 21 13:35:23 2009 +0100

    Location writeback support for XMP formats

 data/ontologies/40-mlo.ontology                |    5 +
 src/libtracker-common/tracker-ontology.h       |    1 +
 src/tracker-extract/tracker-extract-playlist.c |    4 +-
 src/tracker-extract/tracker-xmp.c              |    7 +
 src/tracker-writeback/tracker-writeback-xmp.c  |  148 +++++++++++++++++-------
 5 files changed, 120 insertions(+), 45 deletions(-)
---
diff --git a/data/ontologies/40-mlo.ontology b/data/ontologies/40-mlo.ontology
index a124b7f..ed6cae2 100644
--- a/data/ontologies/40-mlo.ontology
+++ b/data/ontologies/40-mlo.ontology
@@ -95,6 +95,7 @@ mlo:routeDetails a rdf:Property ;
 
 # FIXME Domain rdfs:Resource?? to link files and not only content?
 mlo:location a rdf:Property ;
+    tracker:writeback true ;
     rdfs:label "Property linking something to a location" ;
     rdfs:comment "This can be subclassed to add semantics" ;
     rdfs:domain nie:InformationElement ;
@@ -102,21 +103,25 @@ mlo:location a rdf:Property ;
 
 # TODO: These are ad-hoc added by Philip to support writeback of locations
 mlo:city a rdf:Property ;
+    tracker:writeback true ;
     rdfs:label "City" ;
     rdfs:domain mlo:GeoPoint ;
     rdfs:range  xsd:string .
 
 mlo:country a rdf:Property ;
+    tracker:writeback true ;
     rdfs:label "Country" ;
     rdfs:domain mlo:GeoPoint ;
     rdfs:range  xsd:string .
 
 mlo:state a rdf:Property ;
+    tracker:writeback true ;
     rdfs:label "State" ;
     rdfs:domain mlo:GeoPoint ;
     rdfs:range  xsd:string .
 
 mlo:address a rdf:Property ;
+    tracker:writeback true ;
     rdfs:label "Address" ;
     rdfs:domain mlo:GeoPoint ;
     rdfs:range  xsd:string .
diff --git a/src/libtracker-common/tracker-ontology.h b/src/libtracker-common/tracker-ontology.h
index 537a5e2..ca8cc38 100644
--- a/src/libtracker-common/tracker-ontology.h
+++ b/src/libtracker-common/tracker-ontology.h
@@ -52,6 +52,7 @@ G_BEGIN_DECLS
 
 /* Temporary */
 #define TRACKER_NMM_PREFIX      "http://www.tracker-project.org/temp/nmm#";
+#define TRACKER_MLO_PREFIX      "http://www.tracker-project.org/temp/mlo#";
 
 #define TRACKER_DATASOURCE_URN_PREFIX	  \
 	"urn:nepomuk:datasource:"
diff --git a/src/tracker-extract/tracker-extract-playlist.c b/src/tracker-extract/tracker-extract-playlist.c
index 8bfb299..4311959 100644
--- a/src/tracker-extract/tracker-extract-playlist.c
+++ b/src/tracker-extract/tracker-extract-playlist.c
@@ -94,9 +94,9 @@ entry_parsed (TotemPlParser *parser, const gchar *to_uri, GHashTable *to_metadat
 	tracker_sparql_builder_predicate (data->metadata, "a");
 	tracker_sparql_builder_object (data->metadata, "nie:DataObject");
 	tracker_sparql_builder_predicate (data->metadata, "nie:isStoredAs");
-	tracker_sparql_builder_object_unvalidated (data->metadata, data->uri);
+	tracker_sparql_builder_object_iri (data->metadata, data->uri);
 	tracker_sparql_builder_predicate (data->metadata, "nie:url");
-	tracker_sparql_builder_object_unvalidated (data->metadata, data->uri);
+	tracker_sparql_builder_object_string (data->metadata, data->uri);
 
 	tracker_sparql_builder_predicate (data->metadata, "nfo:entryContent");
 	tracker_sparql_builder_object_unvalidated (data->metadata, to_uri);
diff --git a/src/tracker-extract/tracker-xmp.c b/src/tracker-extract/tracker-xmp.c
index fea2859..140b2e3 100644
--- a/src/tracker-extract/tracker-xmp.c
+++ b/src/tracker-extract/tracker-xmp.c
@@ -373,6 +373,10 @@ tracker_xmp_iter_simple (const gchar          *uri,
 			data->license = g_strdup (value);
 		}
 	} else
+	/* 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 */
+
 	/* Photoshop TODO: is this needed anyway? */
 	if (g_ascii_strcasecmp (schema,  NS_PHOTOSHOP) == 0) {
 		if (data->City && g_ascii_strcasecmp (name, "City") == 0) {
@@ -398,6 +402,9 @@ tracker_xmp_iter_simple (const gchar          *uri,
 		} else 
 		if (!data->Country && g_ascii_strcasecmp (name, "PrimaryLocationName") == 0) {
 			data->Country = g_strdup (value);
+		} else
+		if (!data->State && g_ascii_strcasecmp (name, "State") == 0) {
+			data->State = g_strdup (value);
 		} else 
 		if (!data->State && g_ascii_strcasecmp (name, "Province") == 0) {
 			data->State = g_strdup (value);
diff --git a/src/tracker-writeback/tracker-writeback-xmp.c b/src/tracker-writeback/tracker-writeback-xmp.c
index b396ded..50bdd12 100644
--- a/src/tracker-writeback/tracker-writeback-xmp.c
+++ b/src/tracker-writeback/tracker-writeback-xmp.c
@@ -31,6 +31,7 @@
 #include <gio/gio.h>
 
 #include <libtracker-common/tracker-ontology.h>
+#include <libtracker-common/tracker-utils.h>
 
 #include "tracker-writeback-file.h"
 
@@ -162,26 +163,23 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
 
 			g_free (query);
 
-			if (!error) {
-				if (name_array && name_array->len > 0) {
-					GStrv name_row;
+			if (name_array && name_array->len > 0) {
+				GStrv name_row;
 
-					name_row = g_ptr_array_index (name_array, 0);
+				name_row = g_ptr_array_index (name_array, 0);
 
-					if (name_row[0]) {
-						xmp_delete_property (xmp, NS_DC, "creator");
-						xmp_set_property (xmp, NS_DC, "creator", name_row[0], 0);
-					}
-				}
-
-				if (name_array) {
-					g_ptr_array_foreach (name_array, (GFunc) g_strfreev, NULL);
-					g_ptr_array_free (name_array, TRUE);
+				if (name_row[0]) {
+					xmp_delete_property (xmp, NS_DC, "creator");
+					xmp_set_property (xmp, NS_DC, "creator", name_row[0], 0);
 				}
+			}
 
-			} else {
-				g_clear_error (&error);
+			if (name_array) {
+				g_ptr_array_foreach (name_array, (GFunc) g_strfreev, NULL);
+				g_ptr_array_free (name_array, TRUE);
 			}
+
+			g_clear_error (&error);
 		}
 
 		if (g_strcmp0 (row[1], TRACKER_NCO_PREFIX "contributor") == 0) {
@@ -197,26 +195,23 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
 
 			g_free (query);
 
-			if (!error) {
-				if (name_array && name_array->len > 0) {
-					GStrv name_row;
+			if (name_array && name_array->len > 0) {
+				GStrv name_row;
 
-					name_row = g_ptr_array_index (name_array, 0);
+				name_row = g_ptr_array_index (name_array, 0);
 
-					if (name_row[0]) {
-						xmp_delete_property (xmp, NS_DC, "contributor");
-						xmp_set_property (xmp, NS_DC, "contributor", name_row[0], 0);
-					}
-				}
-
-				if (name_array) {
-					g_ptr_array_foreach (name_array, (GFunc) g_strfreev, NULL);
-					g_ptr_array_free (name_array, TRUE);
+				if (name_row[0]) {
+					xmp_delete_property (xmp, NS_DC, "contributor");
+					xmp_set_property (xmp, NS_DC, "contributor", name_row[0], 0);
 				}
+			}
 
-			} else {
-				g_clear_error (&error);
+			if (name_array) {
+				g_ptr_array_foreach (name_array, (GFunc) g_strfreev, NULL);
+				g_ptr_array_free (name_array, TRUE);
 			}
+
+			g_clear_error (&error);
 		}
 
 		if (g_strcmp0 (row[1], TRACKER_NIE_PREFIX "description") == 0) {
@@ -367,23 +362,90 @@ writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
 			g_free (work_on);
 		}
 
-		/*
-		  if (g_strcmp0 (row[1], PHOTO_HAS "contact") == 0) {
-		  Face recognition on the photos
+		if (g_strcmp0 (row[1], TRACKER_MLO_PREFIX "location") == 0 ||
+		    g_strcmp0 (row[1], TRACKER_MLO_PREFIX "city") == 0     ||
+		    g_strcmp0 (row[1], TRACKER_MLO_PREFIX "country") == 0  ||
+		    g_strcmp0 (row[1], TRACKER_MLO_PREFIX "state") == 0    ||
+		    g_strcmp0 (row[1], TRACKER_MLO_PREFIX "address") == 0) 
+		{
+			GPtrArray *array;
+			GError *error = NULL;
+			gchar *query;
+
+			query = g_strdup_printf ("SELECT ?city ?state ?address ?country "
+			                         "WHERE { <%s> mlo:location ?location . "
+			                                 "OPTIONAL { ?location mlo:address ?address } . "
+			                                 "OPTIONAL { ?location mlo:city ?city } . "
+			                                 "OPTIONAL { ?location mlo:country ?country } . "
+			                                 "OPTIONAL { ?location mlo:state ?state} "
+			                         "}", row[0]);
+
+			array = tracker_resources_sparql_query (client, query, &error);
+
+			g_free (query);
+
+			if (array && array->len > 0) {
+				GStrv qrow;
+
+				qrow = g_ptr_array_index (array, 0);
+
+				/* 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 (qrow[0])) {
+					xmp_delete_property (xmp, NS_IPTC4XMP, "City");
+					xmp_set_property (xmp, NS_IPTC4XMP, "City", qrow[0], 0);
+					xmp_delete_property (xmp, NS_PHOTOSHOP, "City");
+					xmp_set_property (xmp, NS_PHOTOSHOP, "City", qrow[0], 0);
+				}
+				g_free (qrow[0]);
+
+				if (!tracker_is_blank_string (qrow[1])) {
+					xmp_delete_property (xmp, NS_IPTC4XMP, "State");
+					xmp_set_property (xmp, NS_IPTC4XMP, "State", qrow[1], 0);
+					xmp_delete_property (xmp, NS_IPTC4XMP, "Province");
+					xmp_set_property (xmp, NS_IPTC4XMP, "Province", qrow[1], 0);
+					xmp_delete_property (xmp, NS_PHOTOSHOP, "State");
+					xmp_set_property (xmp, NS_PHOTOSHOP, "State", qrow[1], 0);
+				}
+				g_free (qrow[1]);
+
+				if (!tracker_is_blank_string (qrow[2])) {
+					xmp_delete_property (xmp, NS_IPTC4XMP, "SubLocation");
+					xmp_set_property (xmp, NS_IPTC4XMP, "SubLocation", qrow[2], 0);
+					xmp_delete_property (xmp, NS_PHOTOSHOP, "Location");
+					xmp_set_property (xmp, NS_PHOTOSHOP, "Location", qrow[2], 0);
+				}
+				g_free (qrow[2]);
+
+				if (!tracker_is_blank_string (qrow[3])) {
+					xmp_delete_property (xmp, NS_PHOTOSHOP, "Country");
+					xmp_set_property (xmp, NS_PHOTOSHOP, "Country", qrow[3], 0);
+					xmp_delete_property (xmp, NS_IPTC4XMP, "Country");
+					xmp_set_property (xmp, NS_IPTC4XMP, "Country", qrow[3], 0);
+					xmp_delete_property (xmp, NS_IPTC4XMP, "PrimaryLocationName");
+					xmp_set_property (xmp, NS_IPTC4XMP, "PrimaryLocationName", qrow[3], 0);
+				}
+				g_free (qrow[3]);
+
+			}
+
+			if (array) {
+				g_ptr_array_free (array, TRUE);
+			}
+
+			g_clear_error (&error);
+		}
+
+		/* TODO: When a photo contains a known face
+		 * 
+		 * if (g_strcmp0 (row[1], 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);
 		  }
-
-		  if (g_strcmp0 (row[1], LOCATION_PREFIX "country") == 0) {
-		  xmp_delete_property (xmp, NS_PHOTOSHOP, "Country");
-		  xmp_set_array_item (xmp, NS_PHOTOSHOP, "Country", 1, row[2], 0);
-		  }
-
-		  if (g_strcmp0 (row[1], LOCATION_PREFIX "city") == 0) {
-		  xmp_delete_property (xmp, NS_PHOTOSHOP, "City");
-		  xmp_set_array_item (xmp, NS_PHOTOSHOP, "City", 1, row[2], 0);
-		  } */
+		*/
 
 	}
 



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