summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-06 18:23:23 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-06 18:24:05 +0100
commit58369b5f89c57da52a1a52e445e86f2c4929b1d3 (patch)
treefb064e8cf2ee9630dfa07f711ae6814376c7064b
parent503f3bc78b5bed94d6519a7a840b4e75ce2322fd (diff)
downloaddefinitions-58369b5f89c57da52a1a52e445e86f2c4929b1d3.tar.gz
schema: Add conversion tools
Change-Id: Idf4816bdedee112e5c2d13abed95343c0a2b0c9c
-rw-r--r--schema/to-jsonld.py21
-rw-r--r--schema/to-rdfxml.py19
2 files changed, 40 insertions, 0 deletions
diff --git a/schema/to-jsonld.py b/schema/to-jsonld.py
new file mode 100644
index 00000000..e48607fd
--- /dev/null
+++ b/schema/to-jsonld.py
@@ -0,0 +1,21 @@
+# Convert all definitions to JSON-LD.
+
+# Requires RDFLib and SuRF.
+
+import surf
+
+import parse
+
+
+all_data = parse.load_all_morphologies(path='..')
+
+def serialize_to_json_ld(rdflib_graph):
+ context = {
+ "@vocab": "http://baserock.org/definitions/example-schema#",
+ "@language": "en"
+ }
+ # requires rdflib-jsonld Python module.
+ return rdflib_graph.serialize(format='json-ld', indent=4, context=context)
+
+with open('definitions.json-ld', 'w') as f:
+ f.write(serialize_to_json_ld(all_data))
diff --git a/schema/to-rdfxml.py b/schema/to-rdfxml.py
new file mode 100644
index 00000000..fcfb92d6
--- /dev/null
+++ b/schema/to-rdfxml.py
@@ -0,0 +1,19 @@
+# Convert all definitions to RDF-XML.
+
+# RDF-XML isn't a very nice format, but it is widely understood by tools.
+
+import parse
+
+
+all_data = parse.load_all_morphologies(path='..')
+
+def serialize_to_rdf_xml(rdflib_graph):
+ # FIXME: there must be a way to make it use nice prefixes for the
+ # namespaces in the output instead of 'ns1', 'ns2' etc.
+ # FIXME: would be nice if it would output in a stable (sorted) order too. I
+ # think this requires a patch to the 'rdflib.plugins.serializers.rdfxml'
+ # module.
+ return rdflib_graph.serialize(format='application/rdf+xml')
+
+with open('definitions.rdfxml', 'w') as f:
+ f.write(serialize_to_rdf_xml(all_data))