rdflib-jsonld
rdflib-jsonld copied to clipboard
Doesn't interpret newlines with python3
I ran the code from the README.md and I get this output:
b'[\n {\n "@id": "file:///home/liam/fyp/#hasAllergens",\n "@type": [\n "http://www.w3.org/2000/01/rdf-schema#Property"\n ]\n },\n {\n "@id": "file:///home/liam/fyp/#Ingredient",\n "@type": [\n "http://www.w3.org/2000/01/rdf-schema#Class"\n ]\n },\n {\n "@id": "file:///home/liam/fyp/#Menu",\n "@type": [\n "http://www.w3.org/2000/01/rdf-schema#Class"\n ],\n "http://www.w3.org/2000/01/rdf-schema#subClassOf": [\n {\n "@id": "file:///home/liam/fyp/#Collection"\n }\n ]\n },\n {\n "@id": "file:///home/liam/fyp/",\n "http://purl.org/dc/elements/1.1/title": [\n {\n "@value": "Primer - Getting into the Semantic Web and RDF using N3"\n }\n ]\n },\n {\n "@id": "file:///home/liam/fyp/#Recipe",\n "@type": [\n "http://www.w3.org/2000/01/rdf-schema#Class"\n ]\n },\n {\n "@id": "file:///home/liam/fyp/#StageSequence",\n "@type": [\n "http://www.w3.org/2000/01/rdf-schema#Class"\n ]\n },\n {\n "@id": "file:///home/liam/fyp/#Food",\n "@type": [\n "http://www.w3.org/2000/01/rdf-schema#Class"\n ]\n },\n {\n "@id": "file:///home/liam/fyp/#Collection",\n "@type": [\n "http://www.w3.org/2000/01/rdf-schema#Class"\n ]\n }\n]'
b'{\n "@context": {\n "@language": "en",\n "@vocab": "http://purl.org/dc/terms/"\n },\n "@graph": [\n {\n "@id": "file:///home/liam/fyp/#hasAllergens",\n "@type": "http://www.w3.org/2000/01/rdf-schema#Property"\n },\n {\n "@id": "file:///home/liam/fyp/#Ingredient",\n "@type": "http://www.w3.org/2000/01/rdf-schema#Class"\n },\n {\n "@id": "file:///home/liam/fyp/#Menu",\n "@type": "http://www.w3.org/2000/01/rdf-schema#Class",\n "http://www.w3.org/2000/01/rdf-schema#subClassOf": {\n "@id": "file:///home/liam/fyp/#Collection"\n }\n },\n {\n "@id": "file:///home/liam/fyp/",\n "http://purl.org/dc/elements/1.1/title": {\n "@value": "Primer - Getting into the Semantic Web and RDF using N3"\n }\n },\n {\n "@id": "file:///home/liam/fyp/#Recipe",\n "@type": "http://www.w3.org/2000/01/rdf-schema#Class"\n },\n {\n "@id": "file:///home/liam/fyp/#StageSequence",\n "@type": "http://www.w3.org/2000/01/rdf-schema#Class"\n },\n {\n "@id": "file:///home/liam/fyp/#Food",\n "@type": "http://www.w3.org/2000/01/rdf-schema#Class"\n },\n {\n "@id": "file:///home/liam/fyp/#Collection",\n "@type": "http://www.w3.org/2000/01/rdf-schema#Class"\n }\n ]\n}'
The \n
newlines are not interpeted and it's difficult to see the structure of the output. This is the case when using python3
but not python2.7
.
We probably need to tweak the readme.
The code should say:
print(g.serialize(format='json-ld', indent=4).decode())
The default serialization is bytes, not UTF8
Oops - managed to accidentally push the proposed change into the 1.1 branch w/o a pull request. Apologies...
Is this issue still open? As in, do we have to use .decode() after calling .serialize() on a graph?