Open marrog opened 3 years ago
Hi @marrog, I can confirm this is a real issue.
It occurs because csvwlib binds a whole pile of prefixes & namespaces to the rdflib Graph()
(see https://github.com/DerwenAI/csvwlib/blob/master/csvwlib/utils/rdf/Namespaces.py#L13) and then the rdflib-jsonld serializer puts everything in the graph's namespaces list into the context (see https://github.com/RDFLib/rdflib-jsonld/blob/master/rdflib_jsonld/serializer.py#L116). This only occurs for JSON-LD and not any other "default" RDF format because the serializers are completely independent.
A real solution here would be to introduce a checker into the rdflib-jsonld code to ensure only used namespaces are placed into Context. Another solution would be to do a similar thing in csvwlib i.d. only bind used prefixes to the graph.
While I think either or both could be done, I would have to check if it's expected JSON-LD behaviour: perhaps there is no requirement that context be limited in this way - to used context elements only - and there may even be reasons why it's not desired, but I suspect that it is not desired behaviour.
Sorry I don't know already, I'm pretty new to JSON-LD as I'm actually one of the rdflib maintainers and have sort of inherited rdflib-jsonld.
I'm not going to be able to fix this any time soon - I'm preoccupied with merging rdflib-jsonld into rdflib main library and adding JSON-LD 1.1 support - so I'd love any external contributions for this.
Hello there!
Im trying to serialize some RDF graph generated from CSV file by using of package: https://pypi.org/project/csvwlib/ Passing None as format to CSVWConverter.to_rdf() method returns normal instance of rdflib.graph.Graph class.
CSV file content is:
Precisely, what I'm doing:
Printed data is:
My question is:
Why jsonld_data contains all default namespaces as @context even if only one of them (csvw) occurs inside @graph section? Using any of "default" formats as n3 or ttl, returns completely different namespaces:
Result:
Versions of packages:
csvwlib==0.3.2 rdflib==5.0.0 rdflib-jsonld==0.5.0
Please let me know if described behavior is a potential error or not. Is there any way to get the same namespaces in context of json-ld as for n3?