Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a usage of Niklas' JSON-LD serializer instead of the internal one.

  • Loading branch information...
commit 39d3bf2ed8de147294bf12fe6ecac95300668b5a 1 parent 5de8a98
@iherman iherman authored
Showing with 11 additions and 3 deletions.
  1. +2 −0  README.md
  2. +9 −3 pyRdfaExtras/__init__.py
View
2  README.md
@@ -53,6 +53,8 @@ The package primarily depends on:
- html5lib: <https://github.com/html5lib/html5lib-python>
- simplejson: <http://undefined.org/python/#simplejson> (in the additional packages folder), needed if the JSON serialization is used and if the underlying python version is 2.5 or lower
- isodate: <http://hg.proclos.com/isodate> (in the additional packages folder) which, in some cases, is missing and RDFLib complains (?)
+
+At the moment, the JSON-LD serialization depends on an external JSON-LD serializer. The package comes with a simple one, but if Niklas Lindström's rdflib_jsonld package is available, then this will be used. The former is not really maintained; the latter is in github: ,https://github.com/RDFLib/rdflib-jsonld>. Note that, eventually, this serializer will find its way to the core RDFLib distribution.
The package has been tested on Python version 2.5 and higher. Python 2.6 or higher is strongly recommended. The package has been adapted to Python 3, though not yet thoroughly tested, because the html5lib does not have yet a Python 3 version.
View
12 pyRdfaExtras/__init__.py
@@ -26,6 +26,9 @@
_turtle_serializer_name = "my-turtle"
_json_serializer_name = "my-json-ld"
+# import rdflib_jsonld
+# from rdflib_jsonld.serializer import JsonLDSerializer
+
try:
from cStringIO import StringIO
except ImportError:
@@ -81,8 +84,11 @@ def _register_JSON_serializer_3(self) :
if not MyGraph.json_serializer_registered :
from rdflib.plugin import register
from rdflib.serializer import Serializer
- register(_json_serializer_name, Serializer,
- "pyRdfaExtras.serializers.jsonserializer", "JsonSerializer")
+ try :
+ from rdflib_jsonld.serializer import JsonLDSerializer
+ register(_json_serializer_name, Serializer,"rdflib_jsonld.serializer", "JsonLDSerializer")
+ except :
+ register(_json_serializer_name, Serializer,"pyRdfaExtras.serializers.jsonserializer", "JsonSerializer")
MyGraph.json_serializer_registered = True
def _register_XML_serializer_2(self) :
@@ -130,7 +136,7 @@ def serialize(self, format = "xml") :
# I do not have the patience of working out why that is so.
self._register_JSON_serializer_3()
stream = StringIO()
- Graph.serialize(self, format=_json_serializer_name, destination = stream)
+ Graph.serialize(self, format=_json_serializer_name, destination = stream, auto_compact = True, indent = 4)
return stream.getvalue()
elif format == "nt" :
return Graph.serialize(self, format="nt")
Please sign in to comment.
Something went wrong with that request. Please try again.