Last active
June 4, 2019 16:17
-
-
Save kasei/294708b043479cb87e0d801e7b7f1f08 to your computer and use it in GitHub Desktop.
Bug in RDFLib JSON-LD code that drops embedded blank nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from rdflib.serializer import Serializer | |
from rdflib import Graph, URIRef, BNode, Literal | |
from rdflib.namespace import FOAF, DCTERMS | |
g = Graph() | |
spatial = BNode() | |
g.add((URIRef('http://example.org/thing'), DCTERMS.spatial, spatial)) | |
g.add((spatial, FOAF.name, Literal('California'))) | |
context = { | |
'foaf': 'http://xmlns.com/foaf/0.1/', | |
'dcterms': 'http://purl.org/dc/terms/', | |
} | |
### Making this True will omit the `foaf:name "California"` data | |
SHOW_SERIALIZATION_BUG = False | |
if SHOW_SERIALIZATION_BUG: | |
context['dcterms:spatial'] = {'@type': '@id'} | |
b = g.serialize(format='json-ld', context=context, indent=4) | |
print(b.decode("utf-8") ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment