[tracker] Fixed several ontology problems with the push modules
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] Fixed several ontology problems with the push modules
- Date: Mon, 27 Apr 2009 09:25:36 -0400 (EDT)
commit 3aeaf2f71228bfd8666540721803a478128b55a7
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Apr 27 15:19:24 2009 +0200
Fixed several ontology problems with the push modules
---
src/plugins/evolution/tracker-evolution-indexer.c | 159 +++++++++++++++------
src/plugins/kmail/tracker-kmail-indexer.c | 161 +++++++++++++++------
2 files changed, 231 insertions(+), 89 deletions(-)
diff --git a/src/plugins/evolution/tracker-evolution-indexer.c b/src/plugins/evolution/tracker-evolution-indexer.c
index d74ae7b..213d5c1 100644
--- a/src/plugins/evolution/tracker-evolution-indexer.c
+++ b/src/plugins/evolution/tracker-evolution-indexer.c
@@ -41,6 +41,8 @@
#include <libtracker-data/tracker-data-query.h>
#include <libtracker-data/tracker-data-update.h>
+#define TRANSACTION_MAX 200
+
#include "tracker-evolution-indexer.h"
/* These defines/renames are necessary for -glue.h */
@@ -55,27 +57,13 @@
/* Based on data/services/email.metadata */
-#define METADATA_EMAIL TRACKER_NMO_PREFIX "Email"
-#define METADATA_MAILBOXDATA_OBJECT TRACKER_NMO_PREFIX "MailboxDataObject"
-
-#define METADATA_EMAIL_RECIPIENT TRACKER_NMO_PREFIX "to"
-#define METADATA_EMAIL_DATE TRACKER_NMO_PREFIX "receivedDate"
-#define METADATA_EMAIL_SENDER TRACKER_NMO_PREFIX "sender"
-#define METADATA_EMAIL_SUBJECT TRACKER_NMO_PREFIX "subject"
-#define METADATA_EMAIL_SENT_TO TRACKER_NMO_PREFIX "recipient"
-#define METADATA_EMAIL_CC TRACKER_NMO_PREFIX "cc"
-#if 0
-#define METADATA_EMAIL_TEXT TRACKER_NMO_PREFIX "Body"
-#endif
-
#define NIE_DATASOURCE TRACKER_NIE_PREFIX "DataSource"
#define NIE_DATASOURCE_P TRACKER_NIE_PREFIX "dataSource"
-#define RDF_TYPE TRACKER_RDF_PREFIX "type"
-
-#define METADATA_EMAIL_MESSAGE_HEADER TRACKER_NMO_PREFIX "messageHeader"
-#define METADATA_EMAIL_MESSAGE_HEADER_NAME TRACKER_NMO_PREFIX "headerName"
-#define METADATA_EMAIL_MESSAGE_HEADER_VALUE TRACKER_NMO_PREFIX "headerValue"
+#define RDF_PREFIX TRACKER_RDF_PREFIX
+#define NMO_PREFIX TRACKER_NMO_PREFIX
+#define NCO_PREFIX TRACKER_NCO_PREFIX
+#define NAO_PREFIX TRACKER_NAO_PREFIX
#define DATASOURCE_URN "urn:nepomuk:datasource:1cb1eb90-1241-11de-8c30-0800200c9a66"
@@ -252,6 +240,33 @@ get_object_encoding (GMimeObject *object)
}
#endif
+
+static void
+get_email_and_fullname (const gchar *line, gchar **email, gchar **fullname)
+{
+ gchar *ptr = g_utf8_strchr (line, -1, '<');
+
+ if (ptr) {
+ gchar *holder;
+
+ holder = g_strdup (line);
+ ptr = g_utf8_strchr (holder, -1, '<');
+ *ptr = '\0';
+ ptr++;
+ *fullname = holder;
+ holder = ptr;
+ ptr = g_utf8_strchr (ptr, -1, '>');
+ if (ptr) {
+ *ptr = '\0';
+ }
+ *email = g_strdup (holder);
+
+ } else {
+ *email = g_strdup (line);
+ *fullname = NULL;
+ }
+}
+
static void
perform_set (TrackerEvolutionIndexer *object,
const gchar *subject,
@@ -261,15 +276,15 @@ perform_set (TrackerEvolutionIndexer *object,
guint i = 0;
if (!tracker_data_query_resource_exists (DATASOURCE_URN, NULL)) {
- tracker_data_insert_statement (DATASOURCE_URN, RDF_TYPE,
+ tracker_data_insert_statement (DATASOURCE_URN, RDF_PREFIX "type",
NIE_DATASOURCE);
}
- tracker_data_insert_statement (subject, RDF_TYPE,
- METADATA_EMAIL);
+ tracker_data_insert_statement (subject, RDF_PREFIX "type",
+ NMO_PREFIX "Email");
- tracker_data_insert_statement (subject, RDF_TYPE,
- METADATA_MAILBOXDATA_OBJECT);
+ tracker_data_insert_statement (subject, RDF_PREFIX "type",
+ NMO_PREFIX "MailboxDataObject");
tracker_data_insert_statement (subject, NIE_DATASOURCE_P,
DATASOURCE_URN);
@@ -378,8 +393,7 @@ perform_set (TrackerEvolutionIndexer *object,
if (!values[i] || strlen (values[i]) < 1)
goto cont;
- key = g_strdup_printf ("X-Evolution-UserTag-%s", (values[i]));
-
+ key = g_strdup (values[i]);
value = strchr (key, '=');
if (value) {
@@ -387,52 +401,85 @@ perform_set (TrackerEvolutionIndexer *object,
value++;
}
- tracker_data_insert_statement (":1", RDF_TYPE,
- METADATA_EMAIL_MESSAGE_HEADER);
+ tracker_data_insert_statement (":1", RDF_PREFIX "type",
+ NAO_PREFIX "Property");
tracker_data_insert_statement (":1",
- METADATA_EMAIL_MESSAGE_HEADER_NAME,
+ NAO_PREFIX "propertyName",
key);
tracker_data_insert_statement (":1",
- METADATA_EMAIL_MESSAGE_HEADER_VALUE,
+ NAO_PREFIX "propertyValue",
value);
tracker_data_insert_statement (subject,
- METADATA_EMAIL_MESSAGE_HEADER,
- ":1");
+ NAO_PREFIX "hasProperty",
+ ":1");
g_free (key);
}
if (g_strcmp0 (predicates[i], TRACKER_EVOLUTION_PREDICATE_SUBJECT) == 0) {
tracker_data_insert_statement (subject,
- METADATA_EMAIL_SUBJECT,
+ TRACKER_NMO_PREFIX "messageSubject",
values[i]);
}
if (g_strcmp0 (predicates[i], TRACKER_EVOLUTION_PREDICATE_SENT) == 0) {
tracker_data_insert_statement (subject,
- METADATA_EMAIL_DATE,
+ TRACKER_NMO_PREFIX "receivedDate",
values[i]);
}
if (g_strcmp0 (predicates[i], TRACKER_EVOLUTION_PREDICATE_FROM) == 0) {
- tracker_data_insert_statement (subject,
- METADATA_EMAIL_SENDER,
- values[i]);
+ gchar *email_uri, *email = NULL, *fullname = NULL;
+ tracker_data_insert_statement (":1", RDF_PREFIX "type", NCO_PREFIX "Contact");
+ get_email_and_fullname (values[i], &email, &fullname);
+ if (fullname) {
+ tracker_data_insert_statement (":1", NCO_PREFIX "fullname", fullname);
+ g_free (fullname);
+ }
+ email_uri = tracker_uri_printf_escaped ("mailto:%s", email);
+ tracker_data_insert_statement (email_uri, RDF_PREFIX "type", NCO_PREFIX "EmailAddress");
+ tracker_data_insert_statement (email_uri, NCO_PREFIX "emailAddress", email);
+ tracker_data_insert_statement (":1", NCO_PREFIX "hasEmailAddress", email_uri);
+ tracker_data_insert_statement (subject, NMO_PREFIX "from", ":1");
+ g_free (email_uri);
+ g_free (email);
}
if (g_strcmp0 (predicates[i], TRACKER_EVOLUTION_PREDICATE_TO) == 0) {
- tracker_data_insert_statement (subject,
- METADATA_EMAIL_SENT_TO,
- values[i]);
+ gchar *email_uri, *email = NULL, *fullname = NULL;
+ tracker_data_insert_statement (":1", RDF_PREFIX "type", NCO_PREFIX "Contact");
+ get_email_and_fullname (values[i], &email, &fullname);
+ if (fullname) {
+ tracker_data_insert_statement (":1", NCO_PREFIX "fullname", fullname);
+ g_free (fullname);
+ }
+ email_uri = tracker_uri_printf_escaped ("mailto:%s", email);
+ tracker_data_insert_statement (email_uri, RDF_PREFIX "type", NCO_PREFIX "EmailAddress");
+ tracker_data_insert_statement (email_uri, NCO_PREFIX "emailAddress", email);
+ tracker_data_insert_statement (":1", NCO_PREFIX "hasEmailAddress", email_uri);
+ tracker_data_insert_statement (subject, NMO_PREFIX "to", ":1");
+ g_free (email_uri);
+ g_free (email);
}
if (g_strcmp0 (predicates[i], TRACKER_EVOLUTION_PREDICATE_CC) == 0) {
- tracker_data_insert_statement (subject,
- METADATA_EMAIL_CC,
- values[i]);
+ gchar *email_uri, *email = NULL, *fullname = NULL;
+ tracker_data_insert_statement (":1", RDF_PREFIX "type", NCO_PREFIX "Contact");
+ get_email_and_fullname (values[i], &email, &fullname);
+ if (fullname) {
+ tracker_data_insert_statement (":1", NCO_PREFIX "fullname", fullname);
+ g_free (fullname);
+ }
+ email_uri = tracker_uri_printf_escaped ("mailto:%s", email);
+ tracker_data_insert_statement (email_uri, RDF_PREFIX "type", NCO_PREFIX "EmailAddress");
+ tracker_data_insert_statement (email_uri, NCO_PREFIX "emailAddress", email);
+ tracker_data_insert_statement (":1", NCO_PREFIX "hasEmailAddress", email_uri);
+ tracker_data_insert_statement (subject, NMO_PREFIX "cc", ":1");
+ g_free (email_uri);
+ g_free (email);
}
cont:
@@ -502,7 +549,7 @@ tracker_evolution_indexer_set_many (TrackerEvolutionIndexer *object,
GError *derror)
{
guint len;
- guint i = 0;
+ guint i = 0, amount = 0;
dbus_async_return_if_fail (subjects != NULL, context);
dbus_async_return_if_fail (predicates != NULL, context);
@@ -513,17 +560,29 @@ tracker_evolution_indexer_set_many (TrackerEvolutionIndexer *object,
dbus_async_return_if_fail (len == predicates->len, context);
dbus_async_return_if_fail (len == values->len, context);
+ tracker_data_begin_transaction ();
+
while (subjects[i] != NULL) {
GStrv preds = g_ptr_array_index (predicates, i);
GStrv vals = g_ptr_array_index (values, i);
perform_set (object, subjects[i], preds, vals);
+ amount++;
+ if (amount > TRANSACTION_MAX) {
+ tracker_data_commit_transaction ();
+ g_main_context_iteration (NULL, FALSE);
+ tracker_data_begin_transaction ();
+ amount = 0;
+ }
+
i++;
}
set_stored_last_modseq (modseq);
+ tracker_data_commit_transaction ();
+
dbus_g_method_return (context);
}
@@ -534,19 +593,31 @@ tracker_evolution_indexer_unset_many (TrackerEvolutionIndexer *object,
DBusGMethodInvocation *context,
GError *derror)
{
- guint i = 0;
+ guint i = 0, amount = 0;
dbus_async_return_if_fail (subjects != NULL, context);
+ tracker_data_begin_transaction ();
+
while (subjects[i] != NULL) {
perform_unset (object, subjects[i]);
+ amount++;
+ if (amount > TRANSACTION_MAX) {
+ tracker_data_commit_transaction ();
+ g_main_context_iteration (NULL, FALSE);
+ tracker_data_begin_transaction ();
+ amount = 0;
+ }
+
i++;
}
set_stored_last_modseq (modseq);
+ tracker_data_commit_transaction ();
+
dbus_g_method_return (context);
}
diff --git a/src/plugins/kmail/tracker-kmail-indexer.c b/src/plugins/kmail/tracker-kmail-indexer.c
index eb49216..6ae0c72 100644
--- a/src/plugins/kmail/tracker-kmail-indexer.c
+++ b/src/plugins/kmail/tracker-kmail-indexer.c
@@ -46,6 +46,8 @@
#include <tracker-indexer/tracker-push.h>
#include <tracker-indexer/tracker-module-metadata-private.h>
+#define TRANSACTION_MAX 200
+
#include "tracker-kmail-indexer.h"
void tracker_push_module_init (TrackerConfig *config);
@@ -64,32 +66,14 @@ void tracker_push_module_shutdown (void);
/* Based on data/services/email.metadata */
-#define METADATA_EMAIL TRACKER_NMO_PREFIX "Email"
-#define METADATA_MAILBOXDATA_OBJECT TRACKER_NMO_PREFIX "MailboxDataObject"
-
-#define METADATA_EMAIL_RECIPIENT TRACKER_NMO_PREFIX "to"
-#define METADATA_EMAIL_DATE TRACKER_NMO_PREFIX "receivedDate"
-#define METADATA_EMAIL_SENDER TRACKER_NMO_PREFIX "sender"
-#define METADATA_EMAIL_SUBJECT TRACKER_NMO_PREFIX "subject"
-#define METADATA_EMAIL_SENT_TO TRACKER_NMO_PREFIX "recipient"
-#define METADATA_EMAIL_CC TRACKER_NMO_PREFIX "cc"
-#if 0
-#define METADATA_EMAIL_TEXT TRACKER_NMO_PREFIX "Body"
-#endif
+#define RDF_PREFIX TRACKER_RDF_PREFIX
+#define NMO_PREFIX TRACKER_NMO_PREFIX
+#define NCO_PREFIX TRACKER_NCO_PREFIX
+#define NAO_PREFIX TRACKER_NAO_PREFIX
#define NIE_DATASOURCE TRACKER_NIE_PREFIX "DataSource"
#define NIE_DATASOURCE_P TRACKER_NIE_PREFIX "dataSource"
-#define RDF_TYPE TRACKER_RDF_PREFIX "type"
-
-#define METADATA_EMAIL_MESSAGE_HEADER TRACKER_NMO_PREFIX "messageHeader"
-#define METADATA_EMAIL_MESSAGE_HEADER_NAME TRACKER_NMO_PREFIX "headerName"
-#define METADATA_EMAIL_MESSAGE_HEADER_VALUE TRACKER_NMO_PREFIX "headerValue"
-
-#define NAO_TAG TRACKER_NAO_PREFIX "Tag"
-#define NAO_HASTAG TRACKER_NAO_PREFIX "hasTag"
-#define NAO_PREFLABEL TRACKER_NAO_PREFIX "prefLabel"
-
#define DATASOURCE_URN "urn:nepomuk:datasource:4a157cf0-1241-11de-8c30-0800200c9a66"
G_DEFINE_TYPE (TrackerKMailIndexer, tracker_kmail_indexer, G_TYPE_OBJECT)
@@ -154,6 +138,34 @@ tracker_kmail_indexer_init (TrackerKMailIndexer *object)
}
+
+static void
+get_email_and_fullname (const gchar *line, gchar **email, gchar **fullname)
+{
+ gchar *ptr = g_utf8_strchr (line, -1, '<');
+
+ if (ptr) {
+ gchar *holder;
+
+ holder = g_strdup (line);
+ ptr = g_utf8_strchr (holder, -1, '<');
+ *ptr = '\0';
+ ptr++;
+ *fullname = holder;
+ holder = ptr;
+ ptr = g_utf8_strchr (ptr, -1, '>');
+ if (ptr) {
+ *ptr = '\0';
+ }
+ *email = g_strdup (holder);
+
+ } else {
+ *email = g_strdup (line);
+ *fullname = NULL;
+ }
+}
+
+
static void
perform_set (TrackerKMailIndexer *object,
const gchar *subject,
@@ -163,15 +175,16 @@ perform_set (TrackerKMailIndexer *object,
guint i = 0;
if (!tracker_data_query_resource_exists (DATASOURCE_URN, NULL)) {
- tracker_data_insert_statement (DATASOURCE_URN, RDF_TYPE,
+ tracker_data_insert_statement (DATASOURCE_URN, RDF_PREFIX "type",
NIE_DATASOURCE);
}
- tracker_data_insert_statement (subject, RDF_TYPE,
- METADATA_EMAIL);
- tracker_data_insert_statement (subject, RDF_TYPE,
- METADATA_MAILBOXDATA_OBJECT);
+ tracker_data_insert_statement (subject, RDF_PREFIX "type",
+ NMO_PREFIX "Email");
+
+ tracker_data_insert_statement (subject, RDF_PREFIX "type",
+ NMO_PREFIX "MailboxDataObject");
tracker_data_insert_statement (subject, NIE_DATASOURCE_P,
DATASOURCE_URN);
@@ -191,48 +204,82 @@ perform_set (TrackerKMailIndexer *object,
if (g_strcmp0 (predicates[i], TRACKER_KMAIL_PREDICATE_TAG) == 0) {
- tracker_data_insert_statement (":1", RDF_TYPE,
- NAO_TAG);
+ tracker_data_insert_statement (":1", RDF_PREFIX "type",
+ NAO_PREFIX "Tag");
tracker_data_insert_statement (":1",
- NAO_PREFLABEL,
+ NAO_PREFIX "prefLabel",
values[i]);
tracker_data_insert_statement (subject,
- NAO_HASTAG,
+ NAO_PREFIX "hasTag",
":1");
}
if (g_strcmp0 (predicates[i], TRACKER_KMAIL_PREDICATE_SUBJECT) == 0) {
- tracker_data_insert_statement (subject,
- METADATA_EMAIL_SUBJECT,
+ tracker_data_insert_statement (subject,
+ TRACKER_NMO_PREFIX "messageSubject",
values[i]);
}
if (g_strcmp0 (predicates[i], TRACKER_KMAIL_PREDICATE_SENT) == 0) {
tracker_data_insert_statement (subject,
- METADATA_EMAIL_DATE,
+ TRACKER_NMO_PREFIX "receivedDate",
values[i]);
}
if (g_strcmp0 (predicates[i], TRACKER_KMAIL_PREDICATE_FROM) == 0) {
- tracker_data_insert_statement (subject,
- METADATA_EMAIL_SENDER,
- values[i]);
+ gchar *email_uri, *email = NULL, *fullname = NULL;
+ tracker_data_insert_statement (":1", RDF_PREFIX "type", NCO_PREFIX "Contact");
+ get_email_and_fullname (values[i], &email, &fullname);
+ if (fullname) {
+ tracker_data_insert_statement (":1", NCO_PREFIX "fullname", fullname);
+ g_free (fullname);
+ }
+ email_uri = tracker_uri_printf_escaped ("mailto:%s", email);
+ tracker_data_insert_statement (email_uri, RDF_PREFIX "type", NCO_PREFIX "EmailAddress");
+ tracker_data_insert_statement (email_uri, NCO_PREFIX "emailAddress", email);
+ tracker_data_insert_statement (":1", NCO_PREFIX "hasEmailAddress", email_uri);
+ tracker_data_insert_statement (subject, NMO_PREFIX "from", ":1");
+ g_free (email_uri);
+ g_free (email);
}
if (g_strcmp0 (predicates[i], TRACKER_KMAIL_PREDICATE_TO) == 0) {
- tracker_data_insert_statement (subject,
- METADATA_EMAIL_SENT_TO,
- values[i]);
+ gchar *email_uri, *email = NULL, *fullname = NULL;
+ tracker_data_insert_statement (":1", RDF_PREFIX "type", NCO_PREFIX "Contact");
+ get_email_and_fullname (values[i], &email, &fullname);
+ if (fullname) {
+ tracker_data_insert_statement (":1", NCO_PREFIX "fullname", fullname);
+ g_free (fullname);
+ }
+ email_uri = tracker_uri_printf_escaped ("mailto:%s", email);
+ tracker_data_insert_statement (email_uri, RDF_PREFIX "type", NCO_PREFIX "EmailAddress");
+ tracker_data_insert_statement (email_uri, NCO_PREFIX "emailAddress", email);
+ tracker_data_insert_statement (":1", NCO_PREFIX "hasEmailAddress", email_uri);
+ tracker_data_insert_statement (subject, NMO_PREFIX "to", ":1");
+ g_free (email_uri);
+ g_free (email);
}
if (g_strcmp0 (predicates[i], TRACKER_KMAIL_PREDICATE_CC) == 0) {
- tracker_data_insert_statement (subject,
- METADATA_EMAIL_CC,
- values[i]);
+ gchar *email_uri, *email = NULL, *fullname = NULL;
+ tracker_data_insert_statement (":1", RDF_PREFIX "type", NCO_PREFIX "Contact");
+ get_email_and_fullname (values[i], &email, &fullname);
+ if (fullname) {
+ tracker_data_insert_statement (":1", NCO_PREFIX "fullname", fullname);
+ g_free (fullname);
+ }
+ email_uri = tracker_uri_printf_escaped ("mailto:%s", email);
+ tracker_data_insert_statement (email_uri, RDF_PREFIX "type", NCO_PREFIX "EmailAddress");
+ tracker_data_insert_statement (email_uri, NCO_PREFIX "emailAddress", email);
+ tracker_data_insert_statement (":1", NCO_PREFIX "hasEmailAddress", email_uri);
+ tracker_data_insert_statement (subject, NMO_PREFIX "cc", ":1");
+ g_free (email_uri);
+ g_free (email);
}
+
i++;
}
@@ -298,7 +345,7 @@ tracker_kmail_indexer_set_many (TrackerKMailIndexer *object,
GError *derror)
{
guint len;
- guint i = 0;
+ guint i = 0, amount = 0;
dbus_async_return_if_fail (subjects != NULL, context);
dbus_async_return_if_fail (predicates != NULL, context);
@@ -309,17 +356,29 @@ tracker_kmail_indexer_set_many (TrackerKMailIndexer *object,
dbus_async_return_if_fail (len == predicates->len, context);
dbus_async_return_if_fail (len == values->len, context);
+ tracker_data_begin_transaction ();
+
while (subjects[i] != NULL) {
GStrv preds = g_ptr_array_index (predicates, i);
GStrv vals = g_ptr_array_index (values, i);
perform_set (object, subjects[i], preds, vals);
+ amount++;
+ if (amount > TRANSACTION_MAX) {
+ tracker_data_commit_transaction ();
+ g_main_context_iteration (NULL, FALSE);
+ tracker_data_begin_transaction ();
+ amount = 0;
+ }
+
i++;
}
set_stored_last_modseq (modseq);
+ tracker_data_commit_transaction ();
+
dbus_g_method_return (context);
}
@@ -330,19 +389,31 @@ tracker_kmail_indexer_unset_many (TrackerKMailIndexer *object,
DBusGMethodInvocation *context,
GError *derror)
{
- guint i = 0;
+ guint i = 0, amount = 0;
dbus_async_return_if_fail (subjects != NULL, context);
+ tracker_data_begin_transaction ();
+
while (subjects[i] != NULL) {
perform_unset (object, subjects[i]);
+ amount++;
+ if (amount > TRANSACTION_MAX) {
+ tracker_data_commit_transaction ();
+ g_main_context_iteration (NULL, FALSE);
+ tracker_data_begin_transaction ();
+ amount = 0;
+ }
+
i++;
}
set_stored_last_modseq (modseq);
+ tracker_data_commit_transaction ();
+
dbus_g_method_return (context);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]