-
Notifications
You must be signed in to change notification settings - Fork 577
Closed
Labels
Description
whenusing rdflib 6.1.1 to convert the following jsonld to turtle:
{
"slots": [
{
"name": "type",
"slot_uri": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
}
],
"@context": [
{
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@vocab": "https://w3id.org/linkml/",
"slot_uri": {
"@type": "@id"
}
}
]
}
the turtle emitted is:
@prefix : <https://w3id.org/linkml/> .
[] :slots [ :name "type" ;
:slot_uri rdf:type ] .
which is invalid, as it lacks a prefix declaration for rdf
The situation is resolved by either
- adding another node to the graph in the rdf namespace, other than rdf:type
- saving to a format like nt
This reproduces the error:
JSONLD = """
{
"slots": [
{
"name": "type",
"slot_uri": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
}
],
"@context": [
{
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"@vocab": "https://w3id.org/linkml/",
"slot_uri": {
"@type": "@id"
}
}
]
}"""
from rdflib import Graph
graph = Graph()
graph.parse(data=JSONLD, format="json-ld", prefix=False)
ttl_str = graph.serialize(format='turtle')
print(ttl_str)
graph.parse(data=ttl_str, format="turtle")
This is in contrast to other libs, e.g. Jena, which will produce valid turtle:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
_:b0 <https://w3id.org/linkml/slots> _:b1 .
_:b1 <https://w3id.org/linkml/name> "type" ;
<https://w3id.org/linkml/slot_uri> rdf:type .
aucampia