Commit 5df888dd authored by Carlos Garnacho's avatar Carlos Garnacho

Merge branch 'wip/carlosg/drop-sparql-builder' into 'master'

Replace TrackerSparqlBuilder with TrackerResource

See merge request !34
parents f33db522 bc97819a
Pipeline #40388 passed with stage
in 1 minute and 56 seconds
......@@ -63,7 +63,6 @@ typedef struct ProcessFileData ProcessFileData;
struct ProcessFileData {
TrackerMinerFiles *miner;
TrackerSparqlBuilder *sparql;
GCancellable *cancellable;
GFile *file;
gchar *mime_type;
......@@ -2204,18 +2203,15 @@ miner_files_get_file_urn (TrackerMinerFiles *miner,
}
static void
miner_files_add_to_datasource (TrackerMinerFiles *mf,
GFile *file,
TrackerSparqlBuilder *sparql)
miner_files_add_to_datasource (TrackerMinerFiles *mf,
GFile *file,
TrackerResource *resource)
{
TrackerMinerFilesPrivate *priv;
const gchar *removable_device_uuid;
gchar *removable_device_urn, *uri;
const gchar *urn;
gboolean is_iri;
gchar *removable_device_urn;
priv = TRACKER_MINER_FILES_GET_PRIVATE (mf);
uri = g_file_get_uri (file);
removable_device_uuid = tracker_storage_get_uuid_for_file (priv->storage, file);
......@@ -2226,31 +2222,17 @@ miner_files_add_to_datasource (TrackerMinerFiles *mf,
removable_device_urn = g_strdup (TRACKER_DATASOURCE_URN_NON_REMOVABLE_MEDIA);
}
urn = miner_files_get_file_urn (mf, file, &is_iri);
tracker_resource_set_uri (resource, "nie:dataSource", removable_device_urn);
if (is_iri) {
tracker_sparql_builder_subject_iri (sparql, urn);
} else {
tracker_sparql_builder_subject (sparql, urn);
}
tracker_sparql_builder_predicate (sparql, "a");
tracker_sparql_builder_object (sparql, "nfo:FileDataObject");
tracker_sparql_builder_predicate (sparql, "nie:dataSource");
tracker_sparql_builder_object_iri (sparql, removable_device_urn);
tracker_sparql_builder_predicate (sparql, "tracker:available");
tracker_sparql_builder_object_boolean (sparql, TRUE);
tracker_resource_set_boolean (resource, "tracker:available", TRUE);
g_free (removable_device_urn);
g_free (uri);
}
static void
miner_files_add_rdf_types (TrackerSparqlBuilder *sparql,
GFile *file,
const gchar *mime_type)
miner_files_add_rdf_types (TrackerResource *resource,
GFile *file,
const gchar *mime_type)
{
GStrv rdf_types;
gint i = 0;
......@@ -2260,13 +2242,9 @@ miner_files_add_rdf_types (TrackerSparqlBuilder *sparql,
if (!rdf_types)
return;
if (rdf_types[0]) {
tracker_sparql_builder_predicate (sparql, "a");
while (rdf_types[i]) {
tracker_sparql_builder_object (sparql, rdf_types[i]);
i++;
}
while (rdf_types[i]) {
tracker_resource_add_uri (resource, "rdf:type", rdf_types[i]);
i++;
}
g_strfreev (rdf_types);
......@@ -2276,7 +2254,6 @@ static void
process_file_data_free (ProcessFileData *data)
{
g_object_unref (data->miner);
g_object_unref (data->sparql);
g_object_unref (data->cancellable);
g_object_unref (data->file);
g_object_unref (data->task);
......@@ -2284,53 +2261,11 @@ process_file_data_free (ProcessFileData *data)
g_slice_free (ProcessFileData, data);
}
static void
sparql_builder_finish (ProcessFileData *data,
const gchar *preupdate,
const gchar *postupdate,
const gchar *sparql,
const gchar *where)
static gchar *
update_mount_point_sparql (ProcessFileData *data)
{
const gchar *uuid;
if (sparql && *sparql) {
gboolean is_iri;
const gchar *urn;
urn = miner_files_get_file_urn (data->miner, data->file, &is_iri);
if (is_iri) {
gchar *str;
str = g_strdup_printf ("<%s>", urn);
tracker_sparql_builder_append (data->sparql, str);
g_free (str);
} else {
tracker_sparql_builder_append (data->sparql, urn);
}
tracker_sparql_builder_append (data->sparql, sparql);
}
tracker_sparql_builder_graph_close (data->sparql);
tracker_sparql_builder_insert_close (data->sparql);
if (where && *where) {
tracker_sparql_builder_where_open (data->sparql);
tracker_sparql_builder_append (data->sparql, where);
tracker_sparql_builder_where_close (data->sparql);
}
/* Prepend preupdate queries */
if (preupdate && *preupdate) {
tracker_sparql_builder_prepend (data->sparql, preupdate);
}
/* Append postupdate */
if (postupdate && *postupdate) {
tracker_sparql_builder_append (data->sparql, postupdate);
}
uuid = g_object_get_qdata (G_OBJECT (data->file),
data->miner->private->quark_mount_point_uuid);
......@@ -2362,11 +2297,13 @@ sparql_builder_finish (ProcessFileData *data,
"} ",
removable_device_urn, removable_device_urn, uri);
tracker_sparql_builder_append (data->sparql, queries->str);
g_string_free (queries, TRUE);
g_free (removable_device_urn);
g_free (uri);
return g_string_free (queries, FALSE);
}
return NULL;
}
static void
......@@ -2375,20 +2312,20 @@ process_file_cb (GObject *object,
gpointer user_data)
{
TrackerMinerFilesPrivate *priv;
TrackerSparqlBuilder *sparql;
TrackerResource *resource;
ProcessFileData *data;
const gchar *mime_type, *urn, *parent_urn;
gchar *delete_properties_sparql = NULL, *mount_point_sparql;
GFileInfo *file_info;
guint64 time_;
GFile *file, *parent;
gchar *uri;
gchar *uri, *sparql_str, *time_str;
GError *error = NULL;
gboolean is_iri;
gboolean is_directory;
data = user_data;
file = G_FILE (object);
sparql = data->sparql;
file_info = g_file_query_info_finish (file, result, &error);
priv = TRACKER_MINER_FILES (data->miner)->private;
......@@ -2407,8 +2344,6 @@ process_file_cb (GObject *object,
data->mime_type = g_strdup (mime_type);
if (is_iri) {
gchar *delete_properties_sparql;
/* Update: delete all statements inserted by miner except:
* - rdf:type statements as they could cause implicit deletion of user data
* - nie:contentCreated so it persists across updates
......@@ -2436,28 +2371,21 @@ process_file_cb (GObject *object,
TRACKER_OWN_GRAPH_URN, urn,
TRACKER_OWN_GRAPH_URN, urn,
urn, urn);
tracker_sparql_builder_prepend (sparql, delete_properties_sparql);
g_free (delete_properties_sparql);
}
tracker_sparql_builder_insert_silent_open (sparql, NULL);
tracker_sparql_builder_graph_open (sparql, TRACKER_OWN_GRAPH_URN);
resource = tracker_resource_new (NULL);
if (is_iri) {
tracker_sparql_builder_subject_iri (sparql, urn);
} else {
tracker_sparql_builder_subject (sparql, urn);
tracker_resource_set_identifier (resource, urn);
}
tracker_sparql_builder_predicate (sparql, "a");
tracker_sparql_builder_object (sparql, "nfo:FileDataObject");
tracker_sparql_builder_object (sparql, "nie:InformationElement");
tracker_resource_add_uri (resource, "rdf:type", "nfo:FileDataObject");
tracker_resource_add_uri (resource, "rdf:type", "nie:InformationElement");
is_directory = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY ?
TRUE : FALSE);
if (is_directory) {
tracker_sparql_builder_object (sparql, "nfo:Folder");
tracker_resource_add_uri (resource, "rdf:type", "nfo:Folder");
}
parent = g_file_get_parent (file);
......@@ -2465,54 +2393,59 @@ process_file_cb (GObject *object,
g_object_unref (parent);
if (parent_urn) {
tracker_sparql_builder_predicate (sparql, "nfo:belongsToContainer");
tracker_sparql_builder_object_iri (sparql, parent_urn);
tracker_resource_set_uri (resource, "nfo:belongsToContainer", parent_urn);
g_free (parent_urn);
}
tracker_sparql_builder_predicate (sparql, "nfo:fileName");
tracker_sparql_builder_object_string (sparql, g_file_info_get_display_name (file_info));
tracker_sparql_builder_predicate (sparql, "nfo:fileSize");
tracker_sparql_builder_object_int64 (sparql, g_file_info_get_size (file_info));
tracker_resource_set_string (resource, "nfo:fileName",
g_file_info_get_display_name (file_info));
tracker_resource_set_int64 (resource, "nfo:fileSize",
g_file_info_get_size (file_info));
time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
tracker_sparql_builder_predicate (sparql, "nfo:fileLastModified");
tracker_sparql_builder_object_date (sparql, (time_t *) &time_);
time_str = tracker_date_to_string (time_);
tracker_resource_set_string (resource, "nfo:fileLastModified", time_str);
g_free (time_str);
time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_ACCESS);
tracker_sparql_builder_predicate (sparql, "nfo:fileLastAccessed");
tracker_sparql_builder_object_date (sparql, (time_t *) &time_);
time_str = tracker_date_to_string (time_);
tracker_resource_set_string (resource, "nfo:fileLastAccessed", time_str);
g_free (time_str);
/* Laying the link between the IE and the DO. We use IE = DO */
tracker_sparql_builder_predicate (sparql, "nie:isStoredAs");
if (is_iri) {
tracker_sparql_builder_object_iri (sparql, urn);
tracker_resource_add_uri (resource, "nie:isStoredAs", urn);
} else {
tracker_sparql_builder_object (sparql, urn);
tracker_resource_add_relation (resource, "nie:isStoredAs", resource);
}
/* The URL of the DataObject (because IE = DO, this is correct) */
tracker_sparql_builder_predicate (sparql, "nie:url");
tracker_sparql_builder_object_string (sparql, uri);
tracker_resource_set_string (resource, "nie:url", uri);
tracker_sparql_builder_predicate (sparql, "nie:mimeType");
tracker_sparql_builder_object_string (sparql, mime_type);
tracker_resource_set_string (resource, "nie:mimeType", mime_type);
miner_files_add_to_datasource (data->miner, file, sparql);
miner_files_add_to_datasource (data->miner, file, resource);
if (g_file_info_get_size (file_info) > 0)
miner_files_add_rdf_types (sparql, file, mime_type);
miner_files_add_rdf_types (resource, file, mime_type);
mount_point_sparql = update_mount_point_sparql (data);
sparql_str = g_strdup_printf ("%s %s %s",
delete_properties_sparql ? delete_properties_sparql : "",
tracker_resource_print_sparql_update (resource, NULL, TRACKER_OWN_GRAPH_URN),
mount_point_sparql ? mount_point_sparql : "");
g_free (delete_properties_sparql);
g_free (mount_point_sparql);
sparql_builder_finish (data, NULL, NULL, NULL, NULL);
tracker_miner_fs_notify_finish (TRACKER_MINER_FS (data->miner), data->task,
tracker_sparql_builder_get_result (sparql),
NULL);
sparql_str, NULL);
priv->extraction_queue = g_list_remove (priv->extraction_queue, data);
process_file_data_free (data);
g_object_unref (resource);
g_object_unref (file_info);
g_free (sparql_str);
g_free (uri);
}
......@@ -2528,7 +2461,6 @@ miner_files_process_file (TrackerMinerFS *fs,
data = g_slice_new0 (ProcessFileData);
data->miner = g_object_ref (fs);
data->cancellable = g_object_ref (g_task_get_cancellable (task));
data->sparql = tracker_sparql_builder_new_update ();
data->file = g_object_ref (file);
data->task = g_object_ref (task);
......@@ -2558,19 +2490,18 @@ process_file_attributes_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
TrackerSparqlBuilder *sparql;
TrackerResource *resource;
ProcessFileData *data;
const gchar *urn;
GFileInfo *file_info;
guint64 time_;
GFile *file;
gchar *uri;
gchar *uri, *time_str, *sparql_str;
GError *error = NULL;
gboolean is_iri;
data = user_data;
file = G_FILE (object);
sparql = data->sparql;
file_info = g_file_query_info_finish (file, result, &error);
if (error) {
......@@ -2594,67 +2525,31 @@ process_file_attributes_cb (GObject *object,
return;
}
resource = tracker_resource_new (urn);
/* Update nfo:fileLastModified */
tracker_sparql_builder_delete_open (sparql, NULL);
tracker_sparql_builder_subject_iri (sparql, urn);
tracker_sparql_builder_predicate (sparql, "nfo:fileLastModified");
tracker_sparql_builder_object_variable (sparql, "lastmodified");
tracker_sparql_builder_delete_close (sparql);
tracker_sparql_builder_where_open (sparql);
tracker_sparql_builder_subject_iri (sparql, urn);
tracker_sparql_builder_predicate (sparql, "nfo:fileLastModified");
tracker_sparql_builder_object_variable (sparql, "lastmodified");
tracker_sparql_builder_where_close (sparql);
tracker_sparql_builder_insert_open (sparql, NULL);
tracker_sparql_builder_graph_open (sparql, TRACKER_OWN_GRAPH_URN);
tracker_sparql_builder_subject_iri (sparql, urn);
time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
tracker_sparql_builder_predicate (sparql, "nfo:fileLastModified");
tracker_sparql_builder_object_date (sparql, (time_t *) &time_);
tracker_sparql_builder_graph_close (sparql);
tracker_sparql_builder_insert_close (sparql);
time_str = tracker_date_to_string (time_);
tracker_resource_set_string (resource, "nfo:fileLastModified", time_str);
g_free (time_str);
/* Update nfo:fileLastAccessed */
tracker_sparql_builder_delete_open (sparql, NULL);
tracker_sparql_builder_subject_iri (sparql, urn);
tracker_sparql_builder_predicate (sparql, "nfo:fileLastAccessed");
tracker_sparql_builder_object_variable (sparql, "lastaccessed");
tracker_sparql_builder_delete_close (sparql);
tracker_sparql_builder_where_open (sparql);
tracker_sparql_builder_subject_iri (sparql, urn);
tracker_sparql_builder_predicate (sparql, "nfo:fileLastAccessed");
tracker_sparql_builder_object_variable (sparql, "lastaccessed");
tracker_sparql_builder_where_close (sparql);
tracker_sparql_builder_insert_open (sparql, NULL);
tracker_sparql_builder_graph_open (sparql, TRACKER_OWN_GRAPH_URN);
tracker_sparql_builder_subject_iri (sparql, urn);
time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_ACCESS);
tracker_sparql_builder_predicate (sparql, "nfo:fileLastAccessed");
tracker_sparql_builder_object_date (sparql, (time_t *) &time_);
tracker_sparql_builder_graph_close (sparql);
tracker_sparql_builder_insert_close (sparql);
/* Delete data sources from other miners/decorators */
tracker_sparql_builder_delete_open (sparql, NULL);
tracker_sparql_builder_subject_iri (sparql, urn);
tracker_sparql_builder_predicate (sparql, "nie:dataSource");
tracker_sparql_builder_object_variable (sparql, "datasource");
tracker_sparql_builder_delete_close (sparql);
tracker_sparql_builder_where_open (sparql);
tracker_sparql_builder_subject_iri (sparql, urn);
tracker_sparql_builder_predicate (sparql, "nie:dataSource");
tracker_sparql_builder_object_variable (sparql, "datasource");
tracker_sparql_builder_where_close (sparql);
time_str = tracker_date_to_string (time_);
tracker_resource_set_string (resource, "nfo:fileLastAccessed", time_str);
g_free (time_str);
g_object_unref (file_info);
g_free (uri);
/* Notify about the success */
sparql_str = tracker_resource_print_sparql_update (resource, NULL, TRACKER_OWN_GRAPH_URN);
tracker_miner_fs_notify_finish (TRACKER_MINER_FS (data->miner), data->task,
tracker_sparql_builder_get_result (sparql),
NULL);
sparql_str, NULL);
process_file_data_free (data);
g_object_unref (resource);
g_free (sparql_str);
}
static gboolean
......@@ -2668,7 +2563,6 @@ miner_files_process_file_attributes (TrackerMinerFS *fs,
data = g_slice_new0 (ProcessFileData);
data->miner = g_object_ref (fs);
data->cancellable = g_object_ref (g_task_get_cancellable (task));
data->sparql = tracker_sparql_builder_new_update ();
data->file = g_object_ref (file);
data->task = g_object_ref (task);
......
......@@ -555,48 +555,29 @@ feed_channel_change_updated_time_cb (GObject *source,
static gboolean
feed_channel_changed_timeout_cb (gpointer user_data)
{
TrackerSparqlBuilder *sparql;
TrackerResource *resource;
FeedChannelUpdateData *fcud;
gchar *uri;
time_t now;
gchar *uri, *time_str;
fcud = user_data;
fcud->timeout_id = 0;
now = time (NULL);
uri = g_object_get_data (G_OBJECT (fcud->channel), "subject");
g_message ("Updating mfo:updatedTime for channel '%s'", grss_feed_channel_get_title (fcud->channel));
/* I hope there will be soon a SPARQL command to just update a
* value instead to delete and re-insert it
*/
sparql = tracker_sparql_builder_new_update ();
tracker_sparql_builder_delete_open (sparql, NULL);
tracker_sparql_builder_subject_iri (sparql, uri);
tracker_sparql_builder_predicate (sparql, "mfo:updatedTime");
tracker_sparql_builder_object_variable (sparql, "unknown");
tracker_sparql_builder_delete_close (sparql);
tracker_sparql_builder_where_open (sparql);
tracker_sparql_builder_subject_iri (sparql, uri);
tracker_sparql_builder_predicate (sparql, "mfo:updatedTime");
tracker_sparql_builder_object_variable (sparql, "unknown");
tracker_sparql_builder_where_close (sparql);
tracker_sparql_builder_insert_open (sparql, NULL);
tracker_sparql_builder_subject_iri (sparql, uri);
tracker_sparql_builder_predicate (sparql, "mfo:updatedTime");
tracker_sparql_builder_object_date (sparql, &now);
tracker_sparql_builder_insert_close (sparql);
resource = tracker_resource_new (uri);
time_str = tracker_date_to_string (time (NULL));
tracker_resource_set_string (resource, "mfo:updatedTime", time_str);
g_free (time_str);
tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (fcud->miner)),
tracker_sparql_builder_get_result (sparql),
tracker_resource_print_sparql_update (resource, NULL, TRACKER_OWN_GRAPH_URN),
G_PRIORITY_DEFAULT,
fcud->cancellable,
feed_channel_change_updated_time_cb,
fcud);
g_object_unref (sparql);
g_object_unref (resource);
return FALSE;
}
......@@ -660,97 +641,81 @@ feed_fetching_cb (GrssFeedsPool *pool,
}
static gchar *
sparql_add_website (TrackerSparqlBuilder *sparql,
const gchar *uri)
sparql_add_website (TrackerResource *resource,
const gchar *uri)
{
TrackerResource *website;
gchar *website_urn;
website_urn = tracker_sparql_escape_uri_printf ("urn:website:%s", uri);
tracker_sparql_builder_insert_silent_open (sparql, NULL);
tracker_sparql_builder_subject_iri (sparql, website_urn);
tracker_sparql_builder_predicate (sparql, "a");
tracker_sparql_builder_object (sparql, "nie:DataObject");
tracker_sparql_builder_object (sparql, "nfo:Website");
website = tracker_resource_new (website_urn);
tracker_resource_add_uri (website, "rdf:type", "nie:DataObject");
tracker_resource_add_uri (website, "rdf:type", "nfo:Website");
tracker_resource_set_string (website, "nie:url", uri);
tracker_sparql_builder_predicate (sparql, "nie:url");
tracker_sparql_builder_object_unvalidated (sparql, uri);
tracker_sparql_builder_insert_close (sparql);
tracker_resource_set_take_relation (resource, "nco:websiteUrl", website);
return website_urn;
}
static void
sparql_add_contact (TrackerSparqlBuilder *sparql,
const gchar *alias,
GrssPerson *contact,
const gchar *website_urn,
gboolean is_iri)
static TrackerResource *
sparql_add_contact (TrackerResource *resource,
const gchar *property,
GrssPerson *contact)
{
const gchar *name = grss_person_get_name (contact);
const gchar *email = grss_person_get_email (contact);
const gchar *person_url = grss_person_get_uri (contact);
TrackerResource *contact_resource;
tracker_sparql_builder_subject (sparql, alias);
tracker_sparql_builder_predicate (sparql, "a");
tracker_sparql_builder_object (sparql, "nco:Contact");
tracker_sparql_builder_predicate (sparql, "nco:fullname");
tracker_sparql_builder_object_unvalidated (sparql, name);
contact_resource = tracker_resource_new (NULL);
tracker_resource_add_uri (contact_resource, "rdf:type", "nco:Contact");
tracker_resource_set_string (contact_resource, "nco:fullname", name);
if (email != NULL) {
tracker_sparql_builder_predicate (sparql, "nco:hasEmailAddress");
tracker_sparql_builder_object_blank_open (sparql);
TrackerResource *email_resource;
tracker_sparql_builder_predicate (sparql, "a");
tracker_sparql_builder_object (sparql, "nco:EmailAddress");
tracker_sparql_builder_predicate (sparql, "nco:emailAddress");
tracker_sparql_builder_object_unvalidated (sparql, email);
tracker_sparql_builder_object_blank_close (sparql);
email_resource = tracker_resource_new (NULL);
tracker_resource_add_uri (email_resource, "rdf:type", "nco:EmailAddress");
tracker_resource_set_string (email_resource, "nco:emailAddress", email);
tracker_resource_add_take_relation (contact_resource, "nco:hasEmailAddress", email_resource);
}
if (website_urn) {
tracker_sparql_builder_predicate (sparql, "nco:websiteUrl");
if (person_url != NULL)
sparql_add_website (contact_resource, person_url);
if (is_iri) {
tracker_sparql_builder_object_iri (sparql, website_urn);
} else {
tracker_sparql_builder_object (sparql, website_urn);
}
}
tracker_resource_add_take_relation (resource, property, contact_resource);
return contact_resource;
}
static void
sparql_add_enclosure (TrackerSparqlBuilder *sparql,
const gchar *subject,
GrssFeedEnclosure *enclosure)
sparql_add_enclosure (TrackerResource *resource,
GrssFeedEnclosure *enclosure)
{
gchar *url;
TrackerResource *child;
const gchar *url;
gint length;
gchar * format;
const gchar * format;
child = tracker_resource_new (NULL);
url = grss_feed_enclosure_get_url (enclosure);
length = grss_feed_enclosure_get_length (enclosure);
format = grss_feed_enclosure_get_format (enclosure);
tracker_sparql_builder_subject (sparql, subject);
tracker_sparql_builder_predicate (sparql, "a");
tracker_sparql_builder_object (sparql, "mfo:Enclosure");
tracker_sparql_builder_object (sparql, "nfo:RemoteDataObject");
tracker_resource_add_uri (child, "rdf:type", "mfo:Enclosure");
tracker_resource_add_uri (child, "rdf:type", "nfo:RemoteDataObject");
tracker_sparql_builder_predicate (sparql, "mfo:remoteLink");
tracker_sparql_builder_object_unvalidated (sparql, url);
tracker_resource_set_uri (child, "mfo:remoteLink", url);
tracker_sparql_builder_predicate (sparql, "nfo:fileSize");
tracker_sparql_builder_object_int64 (sparql, length);
tracker_resource_set_int64 (child, "nfo:fileSize", length);
if (format != NULL) {
tracker_sparql_builder_predicate (sparql, "nie:mimeType");
tracker_sparql_builder_object_unvalidated (sparql, format);
}
if (format != NULL)
tracker_resource_set_string (child, "nie:mimeType", format);
tracker_resource_add_take_relation (resource, "mfo:enclosureList", child);
}
static gchar *
......@@ -778,187 +743,85 @@ feed_message_create_delete_properties_query (const gchar *item_urn)
"}", item_urn, item_urn);
}
static TrackerSparqlBuilder *
feed_message_create_insert_builder (TrackerMinerRSS *miner,
GrssFeedItem *item,
const gchar *item_urn)
static TrackerResource *
feed_message_create_resource (TrackerMinerRSS *miner,
GrssFeedItem *item,
const gchar *item_urn)
{
time_t t;
gchar *uri;
gchar *uri, *time_str;
const gchar *url;
GrssPerson *author;
gdouble latitude;
gdouble longitude;
const gchar *tmp_string;
TrackerSparqlBuilder *sparql;
TrackerResource *resource;
GrssFeedChannel *channel;
gboolean has_geolocation;
const GList *contributors;
const GList *enclosures;
const GList *list, *l;
GList *contrib_aliases = NULL;
GList *enclosure_aliases = NULL;
GHashTable *websites;
GHashTable *enclosure_urls;
gboolean is_iri = FALSE;
gint i = 0;
if (!item_urn) {
item_urn = "_:message";
} else {
is_iri = TRUE;
}
url = get_message_url (item);
g_message ("Inserting feed item for '%s'", url);
websites = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
g_hash_table_insert (websites, g_strdup (url), g_strdup (item_urn));
resource = tracker_resource_new (item_urn);
tracker_resource_add_uri (resource, "rdf:type", "mfo:FeedMessage");
tracker_resource_add_uri (resource, "rdf:type", "nfo:RemoteDataObject");
sparql = tracker_sparql_builder_new_update ();
if (url != NULL)
tracker_resource_set_string (resource, "nie:url", url);
resource = tracker_resource_new (NULL);
author = grss_feed_item_get_author (item);
contributors = grss_feed_item_get_contributors (item);
channel = grss_feed_item_get_parent (item);
enclosures = grss_feed_item_get_enclosures (item);
for (l = contributors; l; l = l->next) {
const gchar *person_url;
person_url = grss_person_get_uri (l->data);
if (!person_url)
continue;
if (g_hash_table_lookup (websites, person_url))
continue;
g_hash_table_insert (websites, g_strdup (person_url),
sparql_add_website (sparql, person_url));
}
if (author && grss_person_get_uri (author)) {
const gchar *person_url;
person_url = grss_person_get_uri (author);
if (!g_hash_table_lookup (websites, person_url)) {
g_hash_table_insert (websites, g_strdup (person_url),
sparql_add_website (sparql, person_url));
}
}
has_geolocation = grss_feed_item_get_geo_point (item, &latitude, &longitude);
tracker_sparql_builder_insert_open (sparql, NULL);
if (grss_feed_item_get_geo_point (item, &latitude, &longitude)) {
TrackerResource *geolocation;
if (has_geolocation) {
g_message (" Geolocation, using longitude:%f, latitude:%f",
<