Incorrect jsonld expansion in presence of @vocab interacts with expansions of prefixes that use underscores · Issue #2606 · RDFLib/rdflib (original) (raw)
Test case:
{ "classes": [ { "p": "UBERON:0001062", "@type": "Term" } ], "@context": { "@vocab": "http://example.org/", "UBERON": { "@id": "http://purl.obolibrary.org/obo/UBERON_", "@prefix": true }, "p": { "@type": "@id" } } }
In the jsonld playground (https://json-ld.org/playground/), this gets parsed correctly with the compact URI UBERON:0001062
being expanded to <http://purl.obolibrary.org/obo/UBERON_0001062>
_:b0 http://example.org/classes _:b1 .
_:b1 http://example.org/p http://purl.obolibrary.org/obo/UBERON_0001062 .
_:b1 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://example.org/Term .
However, when I convert via rdflib, the compact URI is not expanded, and is oddly downcased:
@prefix : http://example.org/ .
[] :classes [ a :Term ; :p uberon:0001062 ] .
This is true of versions of rdflib from 6.1.0 through to 7.0.0
The correct behavior is rescued if:
- A
/
is used rather than_
- The
@vocab
element is removed
I am using this code to test:
from rdflib import Graph
g = Graph() g.parse( open("test.jsonld"), format="json-ld", ) print(g.serialize(format="turtle"))
My platform is MacOS
I also believe this behavior is not completely deterministic, oddly I don't think I am seeing it on windows when I use windows in github actions, but I have not yet been able to confirm this