tracker r2569 - in branches/turtle: . src/libtracker-data src/tracker-indexer
- From: pvanhoof svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2569 - in branches/turtle: . src/libtracker-data src/tracker-indexer
- Date: Wed, 26 Nov 2008 09:57:45 +0000 (UTC)
Author: pvanhoof
Date: Wed Nov 26 09:57:45 2008
New Revision: 2569
URL: http://svn.gnome.org/viewvc/tracker?rev=2569&view=rev
Log:
2008-11-26 Philip Van Hoof <philip codeminded be>
* src/tracker-indexer/tracker-removable-device.c
* src/libtracker-data/tracker-turtle.c
* src/libtracker-data/tracker-turtle.h: Various fixes for the Turtle
writer. Added turtle writers for metadata fields
Modified:
branches/turtle/ChangeLog
branches/turtle/src/libtracker-data/tracker-turtle.c
branches/turtle/src/libtracker-data/tracker-turtle.h
branches/turtle/src/tracker-indexer/tracker-removable-device.c
Modified: branches/turtle/src/libtracker-data/tracker-turtle.c
==============================================================================
--- branches/turtle/src/libtracker-data/tracker-turtle.c (original)
+++ branches/turtle/src/libtracker-data/tracker-turtle.c Wed Nov 26 09:57:45 2008
@@ -51,27 +51,26 @@
#include <libtracker-data/tracker-data-query.h>
#include <libtracker-data/tracker-data-update.h>
-typedef struct {
- raptor_uri *uri;
- gchar *about_uri;
- raptor_serializer *serializer;
-} ForeachIdentifierInfo;
#endif /* HAVE_RAPTOR */
+static gboolean initialized = FALSE;
+
struct TurtleFile {
- FILE *file;
- raptor_uri *uri;
+ FILE *file;
+#ifdef HAVE_RAPTOR
+ raptor_uri *uri;
raptor_serializer *serializer;
+#endif /* HAVE_RAPTOR */
};
-static gboolean initialized = FALSE;
-
void
tracker_turtle_init (void)
{
if (!initialized) {
+#ifdef HAVE_RAPTOR
raptor_init ();
+#endif /* HAVE_RAPTOR */
initialized = TRUE;
}
}
@@ -80,130 +79,63 @@
tracker_turtle_shutdown (void)
{
if (initialized) {
+#ifdef HAVE_RAPTOR
raptor_finish ();
+#endif /* HAVE_RAPTOR */
initialized = FALSE;
}
}
-#ifdef HAVE_RAPTOR
+#ifdef HAVE_RAPTOR
static void
foreach_in_metadata (TrackerField *field, gpointer value, gpointer user_data)
{
+ raptor_statement *statement;
+ MetadataItem *item = user_data;
+ const gchar *about_uri = item->about_uri;
+ TurtleFile *turtle = item->turtle;
- ForeachIdentifierInfo *info = user_data;
- raptor_statement statement;
-
- statement.subject = info->about_uri;
- statement.subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
- statement.predicate = tracker_field_get_name (field);
- statement.predicate_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
- statement.object = value;
- statement.object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
-
- raptor_serialize_statement (info->serializer,
- &statement);
-}
-
-#endif /* HAVE_RAPTOR */
-
-
-
-void
-tracker_turtle_append (const gchar *turtle_file,
- const gchar *about_uri,
- TrackerDataMetadata *metadata)
-{
-#ifdef HAVE_RAPTOR
- FILE *file = fopen (turtle_file, "a");
-
- /* Similar to a+ */
-
- if (!file)
- file = fopen (turtle_file, "w");
-
- if (file) {
- ForeachIdentifierInfo *info = g_slice_new (ForeachIdentifierInfo);
+ /* TODO: cope with group values by making them ; separated, perhaps by
+ * reading the type from the TrackerField? Also, numeric values don't
+ * need the double quotes (although that might not matter much for
+ * raptor while parsing).
+ *
+ * If you want to reuse the importer of tracker-indexer (for the remov-
+ * able devices), then you'll need to ensure that the predicates
+ * File:Modified and rdf:type are added per record (uyou seperate triples
+ * using a ; and you end a record using a . (a dot).*/
- info->serializer = raptor_new_serializer ("turtle");
+ statement = g_new0 (raptor_statement, 1);
- info->uri = raptor_new_uri (turtle_file);
- info->about_uri = g_strdup_printf ("<%s>", about_uri);
+ statement->subject = (void *) raptor_new_uri (item->about_uri);
+ statement->subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
- raptor_serialize_start_to_file_handle (info->serializer,
- info->uri, file);
+ statement->predicate = (void *) raptor_new_uri (tracker_field_get_name (field));
+ statement->predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
- tracker_data_metadata_foreach (metadata,
- foreach_in_metadata,
- info);
+ statement->object = (unsigned char *) g_strdup (value);
+ statement->object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
- g_free (info->about_uri);
- raptor_free_uri (info->uri);
- raptor_serialize_end (info->serializer);
- raptor_free_serializer(info->serializer);
- g_slice_free (ForeachIdentifierInfo, info);
+ raptor_serialize_statement (turtle->serializer,
+ statement);
- fclose (file);
- }
+ raptor_free_uri ((raptor_uri *) statement->subject);
+ raptor_free_uri ((raptor_uri *) statement->predicate);
+ g_free ((unsigned char *) statement->object);
-#endif /* HAVE_RAPTOR */
+ g_free (statement);
}
+#endif /* HAVE_RAPTOR */
-typedef struct {
- gchar *about_uri;
- TrackerDataMetadata *metadata;
-} MetadataItem;
-
-
-
-void
-tracker_turtle_append_multiple (const gchar *turtle_file, GPtrArray *items)
-{
-#ifdef HAVE_RAPTOR
- FILE *file = fopen (turtle_file, "a");
-
- /* Similar to a+ */
-
- if (!file)
- file = fopen (turtle_file, "w");
-
- if (file) {
- guint cnt;
- ForeachIdentifierInfo *info = g_slice_new (ForeachIdentifierInfo);
-
- info->serializer = raptor_new_serializer ("turtle");
-
- info->uri = raptor_new_uri (turtle_file);
-
- raptor_serialize_start_to_file_handle (info->serializer,
- info->uri, file);
-
- for (cnt = 0; cnt < items->len; cnt++) {
- MetadataItem *item = g_ptr_array_index (items, cnt);
-
- info->about_uri = g_strdup_printf ("<%s>", item->about_uri);
- tracker_data_metadata_foreach (item->metadata,
- foreach_in_metadata,
- info);
- g_free (info->about_uri);
- }
-
- raptor_free_uri (info->uri);
- raptor_serialize_end (info->serializer);
- raptor_free_serializer(info->serializer);
- g_slice_free (ForeachIdentifierInfo, info);
- fclose (file);
- }
-#endif /* HAVE_RAPTOR */
-}
TurtleFile *
tracker_turtle_open (const gchar *turtle_file)
{
#ifdef HAVE_RAPTOR
- TurtleFile *turtle = NULL;
+ TurtleFile *turtle;
turtle = g_new0 (TurtleFile, 1);
@@ -212,10 +144,6 @@
if (!turtle->file)
turtle->file = fopen (turtle_file, "w");
- /*
- * Looks like there's no turtle serializer in Raptor, no worries it's not
- * a hard format to serialize by ourselves.
- */
turtle->serializer = raptor_new_serializer ("turtle");
turtle->uri = raptor_new_uri ("/");
raptor_serialize_start_to_file_handle (turtle->serializer,
@@ -227,47 +155,58 @@
#endif
}
-
-void
-tracker_turtle_add_triple (TurtleFile *turtle,
- const gchar *uri,
- TrackerField *property,
- const gchar *value)
+void
+tracker_turtle_add_metadata (TurtleFile *turtle,
+ const gchar *uri,
+ TrackerDataMetadata *metadata)
{
#ifdef HAVE_RAPTOR
+ MetadataItem *info = g_slice_new (MetadataItem);
- raptor_statement *statement;
-
- /* TODO: cope with group values by making them ; separated, perhaps by
- * reading the type from the TrackerField? Also, numeric values don't
- * need the double quotes (although that might not matter much for
- * raptor while parsing).
- *
- * If you want to reuse the importer of tracker-indexer (for the remov-
- * able devices), then you'll need to ensure that the predicates
- * File:Modified and rdf:type are added per record (uyou seperate triples
- * using a ; and you end a record using a . (a dot).*/
+ info->about_uri = (gchar *) uri;
+ info->metadata = metadata;
+ info->turtle = turtle;
- statement = g_new0 (raptor_statement, 1);
+ tracker_data_metadata_foreach (metadata,
+ foreach_in_metadata,
+ info);
- statement->subject = (void *)raptor_new_uri (uri);
- statement->subject_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
+ g_slice_free (MetadataItem, info);
+#endif /* HAVE_RAPTOR */
+}
- statement->predicate = (void *)raptor_new_uri (tracker_field_get_name (property));
- statement->predicate_type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
+void
+tracker_turtle_add_metadatas (TurtleFile *turtle,
+ GPtrArray *metadata_items)
+{
+#ifdef HAVE_RAPTOR
+ guint cnt;
- statement->object = (unsigned char *)g_strdup (value);
- statement->object_type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
+ for (cnt = 0; cnt < metadata_items->len; cnt++) {
+ MetadataItem *item = g_ptr_array_index (metadata_items, cnt);
- raptor_serialize_statement (turtle->serializer,
- statement);
+ item->turtle = turtle;
- raptor_free_uri ((raptor_uri *)statement->subject);
- raptor_free_uri ((raptor_uri *)statement->predicate);
- g_free ((unsigned char *)statement->object);
+ tracker_data_metadata_foreach (item->metadata,
+ foreach_in_metadata,
+ item);
+ }
+#endif /* HAVE_RAPTOR */
+}
- g_free (statement);
+void
+tracker_turtle_add_triple (TurtleFile *turtle,
+ const gchar *uri,
+ TrackerField *property,
+ const gchar *value)
+{
+#ifdef HAVE_RAPTOR
+ MetadataItem *item = g_slice_new (MetadataItem);
+ item->about_uri = (gchar *) uri;
+ item->turtle = turtle;
+ foreach_in_metadata (property, (gpointer) value, item);
+ g_slice_free (MetadataItem, item);
#endif
}
@@ -279,11 +218,10 @@
raptor_free_uri (turtle->uri);
raptor_serialize_end (turtle->serializer);
raptor_free_serializer(turtle->serializer);
- //fclose (turtle->file);
+ fclose (turtle->file);
raptor_finish ();
g_free (turtle);
#endif
}
-
Modified: branches/turtle/src/libtracker-data/tracker-turtle.h
==============================================================================
--- branches/turtle/src/libtracker-data/tracker-turtle.h (original)
+++ branches/turtle/src/libtracker-data/tracker-turtle.h Wed Nov 26 09:57:45 2008
@@ -24,30 +24,32 @@
#ifndef __TRACKER_TURTLE_H__
#define __TRACKER_TURTLE_H__
-#include "tracker-data-metadata.h"
+#include <libtracker-data/tracker-data-metadata.h>
#include <stdio.h>
typedef struct TurtleFile TurtleFile;
+typedef struct {
+ gchar *about_uri;
+ TrackerDataMetadata *metadata;
+ TurtleFile *turtle; /* For internal use only */
+} MetadataItem;
+
/* Initialization (use in both cases) */
void tracker_turtle_init (void);
void tracker_turtle_shutdown (void);
-
-/* Instant writing access */
-void tracker_turtle_append (const gchar *turtle_file,
- const gchar *about_uri,
- TrackerDataMetadata *metadata);
-void tracker_turtle_append_multiple (const gchar *turtle_file,
- GPtrArray *items);
-
-
/* Transactions style */
TurtleFile *tracker_turtle_open (const gchar *turtle_file);
void tracker_turtle_add_triple (TurtleFile *turtle,
const gchar *uri,
TrackerField *property,
const gchar *value);
+void tracker_turtle_add_metadata (TurtleFile *turtle,
+ const gchar *uri,
+ TrackerDataMetadata *metadata);
+void tracker_turtle_add_metadatas (TurtleFile *turtle,
+ GPtrArray /* <MetadataItem> */ *metadata_items);
void tracker_turtle_close (TurtleFile *turtle);
Modified: branches/turtle/src/tracker-indexer/tracker-removable-device.c
==============================================================================
--- branches/turtle/src/tracker-indexer/tracker-removable-device.c (original)
+++ branches/turtle/src/tracker-indexer/tracker-removable-device.c Wed Nov 26 09:57:45 2008
@@ -172,8 +172,7 @@
TurtleParseInfo *info;
gchar *copy_file, *ptr;
- if (!has_init)
- raptor_init();
+ raptor_init();
parser = raptor_new_parser ("turtle");
@@ -240,7 +239,7 @@
raptor_free_memory (uri_stringb);
- /* raptor_finish(); */
+ raptor_finish();
#endif /* HAVE_RAPTOR */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]