[tracker/wip/sam/resource: 10/15] Enable experimental --output-format=json-ld for TrackerExtract
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/sam/resource: 10/15] Enable experimental --output-format=json-ld for TrackerExtract
- Date: Mon, 18 Apr 2016 16:58:43 +0000 (UTC)
commit fdb034f991c512e7d273b7ad86642f6532ca30ca
Author: Sam Thursfield <sam afuera me uk>
Date: Thu Apr 7 18:34:44 2016 +0100
Enable experimental --output-format=json-ld for TrackerExtract
src/tracker-extract/tracker-extract.c | 88 ++++++++++++++++++++++----------
src/tracker/tracker-extract.c | 8 ++--
2 files changed, 64 insertions(+), 32 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 9ff3c31..d420d7d 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -795,45 +795,77 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
while (task->cur_func) {
if (!filter_module (object, task->cur_module) &&
get_file_metadata (task, &info)) {
- const gchar *preupdate_str, *postupdate_str, *statements_str, *where;
- TrackerSparqlBuilder *builder;
-
no_data_or_modules = FALSE;
- preupdate_str = statements_str = postupdate_str = NULL;
- builder = tracker_extract_info_get_metadata_builder (info);
+ /* This will break in one case or the other depending on what extractor was used...
FIXME */
+ if (output_format == TRACKER_SERIALIZATION_FORMAT_SPARQL) {
+ /* Only works for old-style extractors using TrackerSparqlBuilder */
+ const gchar *preupdate_str, *postupdate_str, *statements_str, *where;
+ TrackerSparqlBuilder *builder;
- if (tracker_sparql_builder_get_length (builder) > 0) {
- statements_str = tracker_sparql_builder_get_result (builder);
- }
+ preupdate_str = statements_str = postupdate_str = NULL;
- builder = tracker_extract_info_get_preupdate_builder (info);
+ builder = tracker_extract_info_get_metadata_builder (info);
- if (tracker_sparql_builder_get_length (builder) > 0) {
- preupdate_str = tracker_sparql_builder_get_result (builder);
- }
+ if (tracker_sparql_builder_get_length (builder) > 0) {
+ statements_str = tracker_sparql_builder_get_result (builder);
+ }
- builder = tracker_extract_info_get_postupdate_builder (info);
+ builder = tracker_extract_info_get_preupdate_builder (info);
- if (tracker_sparql_builder_get_length (builder) > 0) {
- postupdate_str = tracker_sparql_builder_get_result (builder);
- }
+ if (tracker_sparql_builder_get_length (builder) > 0) {
+ preupdate_str = tracker_sparql_builder_get_result (builder);
+ }
+
+ builder = tracker_extract_info_get_postupdate_builder (info);
- where = tracker_extract_info_get_where_clause (info);
+ if (tracker_sparql_builder_get_length (builder) > 0) {
+ postupdate_str = tracker_sparql_builder_get_result (builder);
+ }
- g_print ("\n");
+ where = tracker_extract_info_get_where_clause (info);
- g_print ("SPARQL pre-update:\n--\n%s--\n\n",
- preupdate_str ? preupdate_str : "");
- g_print ("SPARQL item:\n--\n%s--\n\n",
- statements_str ? statements_str : "");
- g_print ("SPARQL where clause:\n--\n%s--\n\n",
- where ? where : "");
- g_print ("SPARQL post-update:\n--\n%s--\n\n",
- postupdate_str ? postupdate_str : "");
+ g_print ("\n");
- tracker_extract_info_unref (info);
- break;
+ g_print ("SPARQL pre-update:\n--\n%s--\n\n",
+ preupdate_str ? preupdate_str : "");
+ g_print ("SPARQL item:\n--\n%s--\n\n",
+ statements_str ? statements_str : "");
+ g_print ("SPARQL where clause:\n--\n%s--\n\n",
+ where ? where : "");
+ g_print ("SPARQL post-update:\n--\n%s--\n\n",
+ postupdate_str ? postupdate_str : "");
+
+ tracker_extract_info_unref (info);
+ break;
+ } else {
+ /* For experimental new TrackerResource extractors */
+ GList *resources = tracker_extract_info_get_resources (info);
+ GError *error = NULL;
+ /* FIXME: we should return a JSON-LD @graph if there are multiple resources,
+ * not a sequence of JSON documents!!!
+ */
+ for (GList *l = resources; l; l = l->next) {
+ char *json;
+
+ /* If this was going into the tracker-store we'd generate a unique ID
+ * here, so that the data persisted across file renames.
+ */
+ tracker_resource_set_identifier (TRACKER_RESOURCE (l->data), uri);
+
+ json = tracker_resource_print_jsonld (TRACKER_RESOURCE (l->data),
&error);
+ if (json) {
+ g_print ("%s\n", json);
+ g_free (json);
+ } else {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ }
+ }
+
+ tracker_extract_info_unref (info);
+ break;
+ }
} else {
if (!tracker_mimetype_info_iter_next (task->mimetype_handlers)) {
break;
diff --git a/src/tracker/tracker-extract.c b/src/tracker/tracker-extract.c
index 5f5b838..6abcf4e 100644
--- a/src/tracker/tracker-extract.c
+++ b/src/tracker/tracker-extract.c
@@ -30,20 +30,20 @@
#include "tracker-config.h"
#include "tracker-extract.h"
-static gchar *output_format = "json-ld";
static gchar *verbosity;
+static gchar *output_format = "json-ld";
static gchar **filenames;
#define EXTRACT_OPTIONS_ENABLED() \
((filenames && g_strv_length (filenames) > 0))
static GOptionEntry entries[] = {
- { "output-format", 'o', 0, G_OPTION_ARG_STRING, &output_format,
- N_("Output results format: 'json' or 'sparql'"),
- N_("FORMAT") },
{ "verbosity", 'v', 0, G_OPTION_ARG_STRING, &verbosity,
N_("Sets the logging verbosity to LEVEL ('debug', 'detailed', 'minimal', 'errors') for all
processes"),
N_("LEVEL") },
+ { "output-format", 'o', 0, G_OPTION_ARG_STRING, &output_format,
+ N_("Output results format: 'json' or 'sparql'"),
+ N_("FORMAT") },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames,
N_("FILE"),
N_("FILE") },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]