[tracker/rss-enclosures] Flickr miner: port writeback to new signal
- From: Roberto Guido <rguido src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/rss-enclosures] Flickr miner: port writeback to new signal
- Date: Wed, 24 Nov 2010 01:35:35 +0000 (UTC)
commit 39fb74e734de20309f203bdb60133c27cda1015d
Author: Adrien Bustany <abustany gnome org>
Date: Wed Aug 25 09:22:06 2010 +0200
Flickr miner: port writeback to new signal
This commit adapts the Flickr miner so that it now follows the new
writeback signal, which sends integers insteads of URIs.
src/miners/flickr/tracker-miner-flickr.vala | 61 +++++++++++++++++---------
1 files changed, 40 insertions(+), 21 deletions(-)
---
diff --git a/src/miners/flickr/tracker-miner-flickr.vala b/src/miners/flickr/tracker-miner-flickr.vala
index 83cde58..59a6acc 100644
--- a/src/miners/flickr/tracker-miner-flickr.vala
+++ b/src/miners/flickr/tracker-miner-flickr.vala
@@ -43,7 +43,6 @@ public class MinerFlickr : Tracker.MinerWeb {
private static const string FLICKR_REST_URL = "http://api.flickr.com/services/rest/";
private static const string FLICKR_PHOTOSET_URL = "http://www.flickr.com/photos/%s/sets/%s";
private static const string FLICKR_PHOTO_URL = "http://farm%s.static.flickr.com/%s/%s_%s.jpg";
- private static const string NMM_PHOTO = "http://www.tracker-project.org/temp/nmm#Photo";
/* Values taken from the EXIF spec */
private enum ExifTag {
@@ -85,6 +84,9 @@ public class MinerFlickr : Tracker.MinerWeb {
/* Used to form some urls */
private string user_id;
+ /* tracker:id of the nmm:Photo class */
+ private int nmm_photo_id;
+
construct {
name = MINER_NAME;
associated = false;
@@ -97,6 +99,7 @@ public class MinerFlickr : Tracker.MinerWeb {
tracker_writeback_connect (writeback, null);
init_datasource ();
+ load_nmm_photo_id ();
this.notify["associated"].connect (association_status_changed);
}
@@ -115,6 +118,23 @@ public class MinerFlickr : Tracker.MinerWeb {
}
}
+ private void load_nmm_photo_id () {
+ Tracker.Sparql.Cursor cursor;
+ string query = "select tracker:id (nmm:Photo) {}";
+
+ nmm_photo_id = -1;
+
+ try {
+ cursor = get_connection ().query (query);
+
+ return_if_fail (cursor.next () == true);
+
+ nmm_photo_id = cursor.get_string (0).to_int ();
+ } catch (Error e) {
+ critical ("Could not load ID of class nmm:Photo: %s", e.message);
+ }
+ }
+
private void association_status_changed (Object source, ParamSpec pspec) {
if (associated) {
if (pull_timeout_handle != 0)
@@ -462,8 +482,9 @@ public class MinerFlickr : Tracker.MinerWeb {
}
}
- private async void writeback_photo (string uri) {
+ private async void writeback_photo (int id) {
Tracker.Sparql.Cursor cursor;
+ string photo_urn;
string photo_id;
string[] local_tags = {};
HashTable<string, string> flickr_tags = new HashTable<string, string> (str_hash, str_equal);
@@ -475,14 +496,18 @@ public class MinerFlickr : Tracker.MinerWeb {
try {
var c = get_connection ();
+ cursor = yield c.query_async ("select tracker:subject (%d) {}".printf (id));
+ return_if_fail (cursor.next () != true);
+ photo_urn = cursor.get_string (0);
+
string s = ("select ?photo_id ?tag where { <%s> nie:dataSource <%s> ;"
+ "nao:identifier ?photo_id ;"
+ "nao:hasTag ?t ."
- + "?t nao:prefLabel ?tag }").printf (uri, DATASOURCE_URN);
+ + "?t nao:prefLabel ?tag }").printf (photo_urn, DATASOURCE_URN);
cursor = yield c.query_async (s, null);
} catch (Error query_error) {
- warning ("Tracker error when doing writeback for photo %s: %s", uri, query_error.message);
+ warning ("Tracker error when doing writeback for photo %d: %s", id, query_error.message);
return;
}
@@ -506,7 +531,7 @@ public class MinerFlickr : Tracker.MinerWeb {
try {
root_node = run_call (tag_call);
} catch (Error get_tags_error) {
- string error_message = "Couldn't get tags for photo %s: %s".printf (uri, get_tags_error.message);
+ string error_message = "Couldn't get tags for photo %s: %s".printf (photo_urn, get_tags_error.message);
status = error_message;
warning (error_message);
return;
@@ -725,24 +750,18 @@ public class MinerFlickr : Tracker.MinerWeb {
associated = false;
}
- public void writeback (HashTable<string, void*> properties)
+ public void writeback (HashTable<int, Array<int>?> properties)
{
- List<weak string> uris = (List<weak string>)properties.get_keys ();
- weak string[] rdf_classes;
-
- foreach (string uri in uris) {
- // This part is not correct anylonger, the hashtable contains IDs
- // instead of string uris
+ properties.foreach ((key, value) => {
+ int id = (int) key;
+ weak Array<int> classes = (Array<int>) value;
- //rdf_classes = (string[])properties.lookup (uri);
-
- //for (uint i = 0; rdf_classes[i] != null; i++) {
- //if (rdf_classes[i] == NMM_PHOTO) {
- //writeback_photo (uri);
- //return;
- //}
- //}
- }
+ for (uint i = 0; i < classes.length; i++) {
+ if (classes.index (i) == nmm_photo_id) {
+ writeback_photo (id);
+ }
+ }
+ });
}
private string? get_resource (string? graph, string[] types, string identifier, out bool created) throws GLib.Error {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]