Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't interpret newlines with python3 #82

Open
leliamesteban opened this issue May 14, 2020 · 3 comments
Open

Doesn't interpret newlines with python3 #82

leliamesteban opened this issue May 14, 2020 · 3 comments

Comments

@leliamesteban
Copy link

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.

@hsolbrig
Copy link
Contributor

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

@hsolbrig
Copy link
Contributor

Oops - managed to accidentally push the proposed change into the 1.1 branch w/o a pull request. Apologies...

@raghav17083
Copy link

Is this issue still open?
As in, do we have to use .decode() after calling .serialize() on a graph?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants