Closed edwardanderson closed 3 years ago
Use pyld instead of rdflib-jsonld. This is how the website generates the json-ld and turtle serializations:
from rdflib import ConjunctiveGraph, URIRef
from pyld.jsonld import expand, to_rdf, JsonLdProcessor, set_document_loader
js = { ... json here ... }
nq = to_rdf(js, {"format": "application/nquads"})
g = ConjunctiveGraph()
for ns in ['crm', 'dc', 'schema', 'dcterms', 'skos', 'la']:
g.bind(ns, ctxt[ns])
g.parse(data=nq, format="nt")
out = g.serialize(format="turtle")
See: https://github.com/linked-art/linked.art/blob/master/extensions/text.py#L413
The way that part
can magically be the right partitioning predicate for different classes is through scoped contexts in the JSON-LD, which it seems that rdflib-jsonld doesn't support.
In the context we define:
"HumanMadeObject": {
"@context": {
"part_of": {
"@id": "crm:P46i_forms_part_of",
"@type": "@id",
"@container": "@set"
},
"part": {
"@id": "crm:P46_is_composed_of",
"@type": "@id",
"@container": "@set"
},
See: https://github.com/linked-art/linked.art/blob/master/content/ns/v1/linked-art.json#L321
Which should only be processed if the current class is HumanMadeObject
.
Thanks so much @azaroth42! I've switched libraries, followed your pattern and have now have working Turtle serialisation :)
I'm working on some Linked Art data processing scripts and I've come across a bug (uncertain where, yet: in my own implementation, in the rdflib-jsonld plugin, or in the
linked-art.json
context?) where certain properties don't serialise.Here is an example:
The
part
data is not present in the output (althoughName
serialises just fine):Is anyone already successfully parsing and serialising Linked Art JSON-LD in Python and would share some tips?