[tracker/wip/carlosg/resources-as-cursors: 6/12] libtracker-sparql: Integrate JSON-LD serializers and deserializers in API
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/resources-as-cursors: 6/12] libtracker-sparql: Integrate JSON-LD serializers and deserializers in API
- Date: Mon, 11 Jul 2022 19:22:38 +0000 (UTC)
commit c1766fdfec1b5fb6659a5a6fff25a301278c575b
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Jul 11 20:31:09 2022 +0200
libtracker-sparql: Integrate JSON-LD serializers and deserializers in API
Add a new TRACKER_RDF_FORMAT_JSON_LD TrackerRdfFormat enum value, and use
the serializer/deserializer objects for those, so that this new value is
accepted in all API that takes this enum.
src/libtracker-sparql/direct/tracker-direct-statement.c | 2 ++
src/libtracker-sparql/direct/tracker-direct.c | 2 ++
src/libtracker-sparql/remote/tracker-http-module.c | 1 +
src/libtracker-sparql/tracker-deserializer.c | 5 +++++
src/libtracker-sparql/tracker-endpoint-http.c | 1 +
src/libtracker-sparql/tracker-enums-private.h | 1 +
src/libtracker-sparql/tracker-enums.h | 1 +
src/libtracker-sparql/tracker-resource.c | 2 ++
src/libtracker-sparql/tracker-serializer.c | 4 ++++
9 files changed, 19 insertions(+)
---
diff --git a/src/libtracker-sparql/direct/tracker-direct-statement.c
b/src/libtracker-sparql/direct/tracker-direct-statement.c
index 8ff95c8fb..d7d1be225 100644
--- a/src/libtracker-sparql/direct/tracker-direct-statement.c
+++ b/src/libtracker-sparql/direct/tracker-direct-statement.c
@@ -216,6 +216,8 @@ convert_format (TrackerRdfFormat format)
return TRACKER_SERIALIZER_FORMAT_TTL;
case TRACKER_RDF_FORMAT_TRIG:
return TRACKER_SERIALIZER_FORMAT_TRIG;
+ case TRACKER_RDF_FORMAT_JSON_LD:
+ return TRACKER_SERIALIZER_FORMAT_JSON_LD;
default:
g_assert_not_reached ();
}
diff --git a/src/libtracker-sparql/direct/tracker-direct.c b/src/libtracker-sparql/direct/tracker-direct.c
index 0cef224e0..3f9ab7fac 100644
--- a/src/libtracker-sparql/direct/tracker-direct.c
+++ b/src/libtracker-sparql/direct/tracker-direct.c
@@ -207,6 +207,8 @@ convert_format (TrackerRdfFormat format)
return TRACKER_SERIALIZER_FORMAT_TTL;
case TRACKER_RDF_FORMAT_TRIG:
return TRACKER_SERIALIZER_FORMAT_TRIG;
+ case TRACKER_RDF_FORMAT_JSON_LD:
+ return TRACKER_SERIALIZER_FORMAT_JSON_LD;
default:
g_assert_not_reached ();
}
diff --git a/src/libtracker-sparql/remote/tracker-http-module.c
b/src/libtracker-sparql/remote/tracker-http-module.c
index 421005001..b9bc78f5c 100644
--- a/src/libtracker-sparql/remote/tracker-http-module.c
+++ b/src/libtracker-sparql/remote/tracker-http-module.c
@@ -40,6 +40,7 @@ static const gchar *mimetypes[] = {
"application/sparql-results+xml",
"text/turtle",
"application/trig",
+ "application/ld+json",
};
G_STATIC_ASSERT (G_N_ELEMENTS (mimetypes) == TRACKER_N_SERIALIZER_FORMATS);
diff --git a/src/libtracker-sparql/tracker-deserializer.c b/src/libtracker-sparql/tracker-deserializer.c
index b1ea33331..0b0d4f8bf 100644
--- a/src/libtracker-sparql/tracker-deserializer.c
+++ b/src/libtracker-sparql/tracker-deserializer.c
@@ -24,6 +24,7 @@
#include "tracker-deserializer.h"
#include "tracker-deserializer-turtle.h"
#include "tracker-deserializer-json.h"
+#include "tracker-deserializer-json-ld.h"
#include "tracker-deserializer-xml.h"
#include "tracker-private.h"
@@ -181,6 +182,8 @@ tracker_deserializer_new (GInputStream *stream,
return tracker_deserializer_turtle_new (stream, namespaces);
case TRACKER_SERIALIZER_FORMAT_TRIG:
return tracker_deserializer_trig_new (stream, namespaces);
+ case TRACKER_SERIALIZER_FORMAT_JSON_LD:
+ return tracker_deserializer_json_ld_new (stream, namespaces);
default:
g_warn_if_reached ();
return NULL;
@@ -197,6 +200,8 @@ pick_format_for_file (GFile *file)
if (g_str_has_suffix (uri, ".trig"))
format = TRACKER_SERIALIZER_FORMAT_TRIG;
+ if (g_str_has_suffix (uri, ".jsonld"))
+ format = TRACKER_SERIALIZER_FORMAT_JSON_LD;
g_free (uri);
diff --git a/src/libtracker-sparql/tracker-endpoint-http.c b/src/libtracker-sparql/tracker-endpoint-http.c
index 52a19458e..e38bb78bb 100644
--- a/src/libtracker-sparql/tracker-endpoint-http.c
+++ b/src/libtracker-sparql/tracker-endpoint-http.c
@@ -64,6 +64,7 @@ const gchar *supported_formats[] = {
"http://www.w3.org/ns/formats/SPARQL_Results_XML",
"http://www.w3.org/ns/formats/Turtle",
"http://www.w3.org/ns/formats/TriG",
+ "http://www.w3.org/ns/formats/JSON-LD",
};
G_STATIC_ASSERT (G_N_ELEMENTS (supported_formats) == TRACKER_N_SERIALIZER_FORMATS);
diff --git a/src/libtracker-sparql/tracker-enums-private.h b/src/libtracker-sparql/tracker-enums-private.h
index e1b0792ae..fe38150f2 100644
--- a/src/libtracker-sparql/tracker-enums-private.h
+++ b/src/libtracker-sparql/tracker-enums-private.h
@@ -28,6 +28,7 @@ typedef enum
TRACKER_SERIALIZER_FORMAT_XML, /* application/sparql-results+xml */
TRACKER_SERIALIZER_FORMAT_TTL, /* text/turtle */
TRACKER_SERIALIZER_FORMAT_TRIG, /* application/trig */
+ TRACKER_SERIALIZER_FORMAT_JSON_LD, /* application/ld+json */
TRACKER_N_SERIALIZER_FORMATS
} TrackerSerializerFormat;
diff --git a/src/libtracker-sparql/tracker-enums.h b/src/libtracker-sparql/tracker-enums.h
index bcbb11359..c89c65e9f 100644
--- a/src/libtracker-sparql/tracker-enums.h
+++ b/src/libtracker-sparql/tracker-enums.h
@@ -25,6 +25,7 @@
typedef enum {
TRACKER_RDF_FORMAT_TURTLE,
TRACKER_RDF_FORMAT_TRIG,
+ TRACKER_RDF_FORMAT_JSON_LD,
TRACKER_N_RDF_FORMATS
} TrackerRdfFormat;
diff --git a/src/libtracker-sparql/tracker-resource.c b/src/libtracker-sparql/tracker-resource.c
index a59d98ebb..7231968d9 100644
--- a/src/libtracker-sparql/tracker-resource.c
+++ b/src/libtracker-sparql/tracker-resource.c
@@ -1668,6 +1668,8 @@ convert_format (TrackerRdfFormat format)
return TRACKER_SERIALIZER_FORMAT_TTL;
case TRACKER_RDF_FORMAT_TRIG:
return TRACKER_SERIALIZER_FORMAT_TRIG;
+ case TRACKER_RDF_FORMAT_JSON_LD:
+ return TRACKER_SERIALIZER_FORMAT_JSON_LD;
case TRACKER_N_RDF_FORMATS:
g_assert_not_reached ();
}
diff --git a/src/libtracker-sparql/tracker-serializer.c b/src/libtracker-sparql/tracker-serializer.c
index a95961d92..f6a72f9fd 100644
--- a/src/libtracker-sparql/tracker-serializer.c
+++ b/src/libtracker-sparql/tracker-serializer.c
@@ -23,6 +23,7 @@
#include "tracker-serializer.h"
#include "tracker-serializer-json.h"
+#include "tracker-serializer-json-ld.h"
#include "tracker-serializer-trig.h"
#include "tracker-serializer-turtle.h"
#include "tracker-serializer-xml.h"
@@ -165,6 +166,9 @@ tracker_serializer_new (TrackerSparqlCursor *cursor,
case TRACKER_SERIALIZER_FORMAT_TRIG:
type = TRACKER_TYPE_SERIALIZER_TRIG;
break;
+ case TRACKER_SERIALIZER_FORMAT_JSON_LD:
+ type = TRACKER_TYPE_SERIALIZER_JSON_LD;
+ break;
default:
g_warn_if_reached ();
return NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]