[tracker/coalesce] Added the sparql-update statements to the jpeg extractor (to be squashed with previous commit)



commit 13e64b456858133529345c66a8411b373bce73d3
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Sep 3 12:35:15 2009 +0200

    Added the sparql-update statements to the jpeg extractor (to be squashed with previous commit)

 src/tracker-extract/tracker-extract-jpeg.c |  224 ++++++++++++++++++++++------
 1 files changed, 180 insertions(+), 44 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c
index 6dcb63c..3e7612d 100644
--- a/src/tracker-extract/tracker-extract-jpeg.c
+++ b/src/tracker-extract/tracker-extract-jpeg.c
@@ -81,9 +81,9 @@
 
 typedef struct {
 	gchar *camera, *title, *orientation, *copyright, *white_balance, 
-	      *fnumber, *flash, *focal_length, *time_original, *artist, 
+	      *fnumber, *flash, *focal_length, *artist, 
 	      *exposure_time, *iso_speed_ratings, *date, *description,
-	      *metering_mode;
+	      *metering_mode, *creator;
 } JpegNeedsMergeData;
 
 static void extract_jpeg (const gchar *filename,
@@ -108,6 +108,31 @@ static void tracker_extract_jpeg_error_exit (j_common_ptr cinfo)
 }
 
 static void
+insert_keywords (TrackerSparqlBuilder *metadata, const gchar *uri, gchar *keywords)
+{
+	char *lasts, *keyw;
+	size_t len;
+
+	keyw = keywords;
+	keywords = strchr (keywords, '"');
+	if (keywords)
+		keywords++;
+	else 
+		keywords = keyw;
+
+	len = strlen (keywords);
+	if (keywords[len - 1] == '"')
+		keywords[len - 1] = '\0';
+
+	for (keyw = strtok_r (keywords, ",; ", &lasts); keyw; 
+	     keyw = strtok_r (NULL, ",; ", &lasts)) {
+		tracker_statement_list_insert (metadata, uri, 
+		                               NIE_PREFIX "keyword", 
+		                               (const gchar*) keyw);
+	}
+}
+
+static void
 extract_jpeg (const gchar *uri,
 	      TrackerSparqlBuilder   *metadata)
 {
@@ -268,9 +293,6 @@ extract_jpeg (const gchar *uri,
 		merge_data.focal_length =  tracker_coalesce (2, exif_data.focal_length,
 		                                             xmp_data.FocalLength);
 
-		merge_data.time_original =  tracker_coalesce (2, exif_data.time_original,
-		                                              xmp_data.DateTimeOriginal);
-
 		merge_data.artist =  tracker_coalesce (2, exif_data.artist,
 		                                       xmp_data.Artist,
 		                                       xmp_data.contributor);
@@ -281,64 +303,178 @@ extract_jpeg (const gchar *uri,
 		merge_data.iso_speed_ratings =  tracker_coalesce (2, exif_data.iso_speed_ratings,
 		                                                  xmp_data.ISOSpeedRatings);
 
-		merge_data.date =  tracker_coalesce (3, exif_data.time, 
+		merge_data.date =  tracker_coalesce (5, exif_data.time, 
 		                                     xmp_data.date,
-		                                     iptc_data.date_created);
+		                                     iptc_data.date_created,
+		                                     exif_data.time_original,
+		                                     xmp_data.DateTimeOriginal);
 
 		merge_data.description = tracker_coalesce (2, exif_data.description,
 		                                           xmp_data.description);
 
-		
-
 		merge_data.metering_mode =  tracker_coalesce (2, exif_data.metering_mode,
 		                                              xmp_data.MeteringMode);
 
+		merge_data.creator =  tracker_coalesce (3, iptc_data.byline,
+		                                        xmp_data.creator,
+		                                        iptc_data.credit);
 
-		g_free (exif_data.user_comment);
+		if (exif_data.user_comment) {
+			tracker_statement_list_insert (metadata, uri, NIE_PREFIX "comment", exif_data.user_comment);
+			g_free (exif_data.user_comment);
+		}
 
+		/* Prioritize on native dimention in all cases */
 		tracker_statement_list_insert_with_int (metadata, uri,
 						   NFO_PREFIX "width",
 						   cinfo.image_width);
+		g_free (exif_data.x_dimention);
+
 		tracker_statement_list_insert_with_int (metadata, uri,
 						   NFO_PREFIX "height",
 						    cinfo.image_height);
-
 		g_free (exif_data.y_dimention);
-		g_free (exif_data.x_dimention);
 
-		g_free (xmp_data.creator);
-		g_free (xmp_data.keywords);
-		g_free (xmp_data.subject);
-		g_free (xmp_data.publisher);
-		g_free (xmp_data.type);
-		g_free (xmp_data.format);
-		g_free (xmp_data.identifier);
-		g_free (xmp_data.source);
-		g_free (xmp_data.language);
-		g_free (xmp_data.relation);
-		g_free (xmp_data.coverage);
-		g_free (xmp_data.license);
-
-		g_free (iptc_data.keywords);
-		g_free (iptc_data.byline);
-		g_free (iptc_data.credit);
-
-		g_free (merge_data.camera);
-		g_free (merge_data.title);
-		g_free (merge_data.orientation);
-		g_free (merge_data.copyright);
-		g_free (merge_data.white_balance);
-		g_free (merge_data.fnumber);
-		g_free (merge_data.flash);
-		g_free (merge_data.focal_length);
-		g_free (merge_data.time_original);
-		g_free (merge_data.artist);
-		g_free (merge_data.exposure_time);
-		g_free (merge_data.iso_speed_ratings);
-		g_free (merge_data.date);
-		g_free (merge_data.description);
-		g_free (merge_data.metering_mode);
+		if (xmp_data.keywords) {
+			insert_keywords (metadata, uri, xmp_data.keywords);
+			g_free (xmp_data.keywords);
+		}
+
+		if (xmp_data.subject) {
+			insert_keywords (metadata, uri, xmp_data.subject);
+			g_free (xmp_data.subject);
+		}
+
+		if (xmp_data.publisher) {
+			tracker_statement_list_insert (metadata, ":", RDF_PREFIX "type", NCO_PREFIX "Contact");
+			tracker_statement_list_insert (metadata, ":", NCO_PREFIX "fullname", xmp_data.publisher);
+			tracker_statement_list_insert (metadata, uri, NCO_PREFIX "publisher", ":");
+			g_free (xmp_data.publisher);
+		}
+
+		if (xmp_data.type) {
+			tracker_statement_list_insert (metadata, uri, DC_PREFIX "type", xmp_data.type);
+			g_free (xmp_data.type);
+		}
+
+		if (xmp_data.format) {
+			tracker_statement_list_insert (metadata, uri, DC_PREFIX "format", xmp_data.format);
+			g_free (xmp_data.format);
+		}
+
+		if (xmp_data.identifier) {
+			tracker_statement_list_insert (metadata, uri, DC_PREFIX "identifier", xmp_data.identifier);
+			g_free (xmp_data.identifier);
+		}
+
+		if (xmp_data.source) {
+			tracker_statement_list_insert (metadata, uri, DC_PREFIX "source", xmp_data.source);
+			g_free (xmp_data.source);
+		}
+
+		if (xmp_data.language) {
+			tracker_statement_list_insert (metadata, uri, DC_PREFIX "language", xmp_data.language);
+			g_free (xmp_data.language);
+		}
+
+		if (xmp_data.relation) {
+			tracker_statement_list_insert (metadata, uri, DC_PREFIX "relation", xmp_data.relation);
+			g_free (xmp_data.relation);
+		}
+
+		if (xmp_data.coverage) {
+			tracker_statement_list_insert (metadata, uri, DC_PREFIX "coverage", xmp_data.coverage);
+			g_free (xmp_data.coverage);
+		}
+
+		if (xmp_data.license) {
+			tracker_statement_list_insert (metadata, uri, NIE_PREFIX "license", xmp_data.license);
+			g_free (xmp_data.license);
+		}
 
+		if (iptc_data.keywords) {
+			insert_keywords (metadata, uri, iptc_data.keywords);
+			g_free (iptc_data.keywords);
+		}
+
+		if (merge_data.camera) {
+			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "camera", merge_data.camera);
+			g_free (merge_data.camera);
+		}
+
+		if (merge_data.title) {
+			tracker_statement_list_insert (metadata, uri, NIE_PREFIX "title", merge_data.title);
+			g_free (merge_data.title);
+		}
+
+		if (merge_data.orientation) {
+			tracker_statement_list_insert (metadata, uri, NFO_PREFIX "orientation", merge_data.orientation);
+			g_free (merge_data.orientation);
+		}
+
+		if (merge_data.copyright) {
+			tracker_statement_list_insert (metadata, uri, NIE_PREFIX "copyright", merge_data.copyright);
+			g_free (merge_data.copyright);
+		}
+
+		if (merge_data.white_balance) {
+			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "whiteBalance", merge_data.white_balance);
+			g_free (merge_data.white_balance);
+		}
+
+		if (merge_data.fnumber) {
+			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "fnumber", merge_data.fnumber);
+			g_free (merge_data.fnumber);
+		}
+
+		if (merge_data.flash) {
+			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "flash", merge_data.flash);
+			g_free (merge_data.flash);
+		}
+
+		if (merge_data.focal_length) {
+			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "focalLength", merge_data.focal_length);
+			g_free (merge_data.focal_length);
+		}
+
+		if (merge_data.artist) {
+			tracker_statement_list_insert (metadata, ":", RDF_PREFIX "type", NCO_PREFIX "Contact");
+			tracker_statement_list_insert (metadata, ":", NCO_PREFIX "fullname", merge_data.artist);
+			tracker_statement_list_insert (metadata, uri, NCO_PREFIX "contributor", ":");
+			g_free (merge_data.artist);
+		}
+
+		if (merge_data.exposure_time) {
+			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "exposureTime", merge_data.exposure_time);
+			g_free (merge_data.exposure_time);
+		}
+
+		if (merge_data.iso_speed_ratings) {
+			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "isoSpeed", merge_data.iso_speed_ratings);
+			g_free (merge_data.iso_speed_ratings);
+		}
+
+		if (merge_data.date) {
+			tracker_statement_list_insert (metadata, uri, NIE_PREFIX "contentCreated", merge_data.date);
+			g_free (merge_data.date);
+		}
+
+		if (merge_data.description) {
+			tracker_statement_list_insert (metadata, uri, NIE_PREFIX "description", merge_data.description);
+			g_free (merge_data.description);
+		}
+
+		if (merge_data.metering_mode) {
+			tracker_statement_list_insert (metadata, uri, NMM_PREFIX "meteringMode", merge_data.metering_mode);
+			g_free (merge_data.metering_mode);
+		}
+
+		if (merge_data.creator) {
+			tracker_statement_list_insert (metadata, ":", RDF_PREFIX "type", NCO_PREFIX "Contact");
+			tracker_statement_list_insert (metadata, ":", NCO_PREFIX "fullname", merge_data.creator);
+			tracker_statement_list_insert (metadata, uri, NCO_PREFIX "creator", ":");
+			g_free (merge_data.creator);
+		}
 
 		jpeg_destroy_decompress (&cinfo);
 fail:



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