Commit 3acc9ea0 authored by Martyn Russell's avatar Martyn Russell

libtracker-extract: Support graph in tracker_xmp_apply_regions()

parent 51d607cd
......@@ -1179,7 +1179,7 @@ tracker_xmp_apply (TrackerSparqlBuilder *preupdate,
if (data->regions) {
tracker_xmp_apply_regions (preupdate, metadata, where, uri, data);
tracker_xmp_apply_regions (preupdate, metadata, graph, where, uri, data);
}
return TRUE;
......@@ -1188,12 +1188,12 @@ tracker_xmp_apply (TrackerSparqlBuilder *preupdate,
gboolean
tracker_xmp_apply_regions (TrackerSparqlBuilder *preupdate,
TrackerSparqlBuilder *metadata,
const gchar *graph,
GString *where,
const gchar *uri,
TrackerXmpData *data)
{
GSList *iter;
TrackerXmpRegion *region;
g_return_val_if_fail (TRACKER_SPARQL_IS_BUILDER (preupdate), FALSE);
g_return_val_if_fail (TRACKER_SPARQL_IS_BUILDER (preupdate), FALSE);
......@@ -1205,19 +1205,20 @@ tracker_xmp_apply_regions (TrackerSparqlBuilder *preupdate,
}
for (iter = data->regions; iter != NULL; iter = iter->next) {
gchar *reguuid;
TrackerXmpRegion *region;
gchar *uuid;
reguuid = tracker_sparql_get_uuid_urn ();
region = (TrackerXmpRegion *) iter->data;
uuid = tracker_sparql_get_uuid_urn ();
tracker_sparql_builder_predicate (metadata, "nfo:hasRegionOfInterest");
tracker_sparql_builder_object_iri (metadata, reguuid);
tracker_sparql_builder_insert_open (preupdate, NULL);
tracker_sparql_builder_subject_iri (preupdate, reguuid);
tracker_sparql_builder_insert_open (preupdate, NULL);
if (graph) {
tracker_sparql_builder_graph_open (preupdate, graph);
}
tracker_sparql_builder_predicate (preupdate, "a");
tracker_sparql_builder_object (preupdate, "nfo:RegionOfInterest");
tracker_sparql_builder_subject_iri (preupdate, uuid);
tracker_sparql_builder_predicate (preupdate, "a");
tracker_sparql_builder_object (preupdate, "nfo:RegionOfInterest");
if (region->title) {
tracker_sparql_builder_predicate (preupdate, "nie:title");
......@@ -1254,12 +1255,9 @@ tracker_xmp_apply_regions (TrackerSparqlBuilder *preupdate,
tracker_sparql_builder_object_unvalidated (preupdate, region->height);
}
tracker_sparql_builder_insert_close (preupdate);
if (region->link_uri && region->link_class) {
tracker_sparql_builder_insert_open (preupdate, NULL);
tracker_sparql_builder_subject_iri (preupdate, reguuid);
tracker_sparql_builder_subject_variable (preupdate, "region");
tracker_sparql_builder_predicate (preupdate, "nfo:roiRefersTo");
tracker_sparql_builder_object_iri (preupdate, region->link_uri);
tracker_sparql_builder_insert_close (preupdate);
......@@ -1271,7 +1269,16 @@ tracker_xmp_apply_regions (TrackerSparqlBuilder *preupdate,
tracker_sparql_builder_where_close (preupdate);
}
g_free (reguuid);
if (graph) {
tracker_sparql_builder_graph_close (preupdate);
}
tracker_sparql_builder_insert_close (preupdate);
/* Handle non-preupdate metadata */
tracker_sparql_builder_predicate (metadata, "nfo:hasRegionOfInterest");
tracker_sparql_builder_object_iri (metadata, uuid);
g_free (uuid);
}
return TRUE;
......
......@@ -118,6 +118,7 @@ gboolean tracker_xmp_apply (TrackerSparqlBuilder *preupdate,
TrackerXmpData *data);
gboolean tracker_xmp_apply_regions (TrackerSparqlBuilder *preupdate,
TrackerSparqlBuilder *metadata,
const gchar *graph,
GString *where,
const gchar *uri,
TrackerXmpData *data);
......
......@@ -435,7 +435,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
}
if (xd->regions) {
tracker_xmp_apply_regions (preupdate, metadata, where, uri, xd);
tracker_xmp_apply_regions (preupdate, metadata, graph, where, uri, xd);
}
if (id->keywords) {
......
......@@ -599,7 +599,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
}
if (xd->regions) {
tracker_xmp_apply_regions (preupdate, metadata, where, uri, xd);
tracker_xmp_apply_regions (preupdate, metadata, graph, NULL, uri, xd);
}
tracker_xmp_free (xd);
......
......@@ -487,7 +487,7 @@ tracker_extract_get_metadata (TrackerExtractInfo *info)
}
if (xd->regions) {
tracker_xmp_apply_regions (preupdate, metadata, where, uri, xd);
tracker_xmp_apply_regions (preupdate, metadata, graph, NULL, uri, xd);
}
if (md.address || md.state || md.country || md.city ||
......
......@@ -387,10 +387,10 @@ test_xmp_regions (void)
data = tracker_xmp_new (contents, size, "test://file");
g_assert_cmpint (2, ==, g_list_length (data->regions));
g_assert_cmpint (2, ==, g_slist_length (data->regions));
/* Regions are stacked while parsing.*/
region = g_list_nth_data (data->regions, 0);
region = g_slist_nth_data (data->regions, 0);
g_assert_cmpstr (region->x, ==, "0.51");
g_assert_cmpstr (region->y, ==, "0.51");
g_assert_cmpstr (region->width, ==, "0.01");
......@@ -399,7 +399,7 @@ test_xmp_regions (void)
g_assert_cmpstr (region->title, ==, "Fido");
g_assert_cmpstr (region->description, ==, "Fido looks happy!");
region = g_list_nth_data (data->regions, 1);
region = g_slist_nth_data (data->regions, 1);
g_assert_cmpstr (region->x, ==, "0.5");
g_assert_cmpstr (region->y, ==, "0.5");
g_assert_cmpstr (region->width, ==, "0.06");
......@@ -430,9 +430,9 @@ test_xmp_regions_quill (void)
data = tracker_xmp_new (contents, size, "test://file");
g_assert_cmpint (2, ==, g_list_length (data->regions));
g_assert_cmpint (2, ==, g_slist_length (data->regions));
region = g_list_nth_data (data->regions, 0);
region = g_slist_nth_data (data->regions, 0);
g_assert_cmpstr (region->x, ==, "0.4");
g_assert_cmpstr (region->y, ==, "0.3");
g_assert_cmpstr (region->width, ==, "0.17");
......@@ -442,7 +442,7 @@ test_xmp_regions_quill (void)
g_assert_cmpstr (region->link_class, ==, "nco:PersonContact");
g_assert_cmpstr (region->link_uri, ==, "urn:uuid:2");
region = g_list_nth_data (data->regions, 1);
region = g_slist_nth_data (data->regions, 1);
g_assert_cmpstr (region->x, ==, "0.3");
g_assert_cmpstr (region->y, ==, "0.4");
g_assert_cmpstr (region->width, ==, "0.15");
......@@ -473,10 +473,10 @@ test_xmp_regions_ns_prefix (void)
data = tracker_xmp_new (contents, size, "test://file");
g_assert_cmpint (2, ==, g_list_length (data->regions));
g_assert_cmpint (2, ==, g_slist_length (data->regions));
/* Regions are stacked while parsing.*/
region = g_list_nth_data (data->regions, 0);
region = g_slist_nth_data (data->regions, 0);
g_assert_cmpstr (region->x, ==, "0.51");
g_assert_cmpstr (region->y, ==, "0.51");
g_assert_cmpstr (region->width, ==, "0.01");
......@@ -485,7 +485,7 @@ test_xmp_regions_ns_prefix (void)
g_assert_cmpstr (region->title, ==, "Fidoz");
g_assert_cmpstr (region->description, ==, "Fido looks happy!");
region = g_list_nth_data (data->regions, 1);
region = g_slist_nth_data (data->regions, 1);
g_assert_cmpstr (region->x, ==, "0.5");
g_assert_cmpstr (region->y, ==, "0.5");
g_assert_cmpstr (region->width, ==, "0.06");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment