json-ld parser adds trailing slash to URLs that have no path · Issue #1443 · RDFLib/rdflib (original) (raw)
This is best described with an example. Here is a json-ld file that contains a URL that has no path:
[ { "@id": "https://sbolstandard.org/examples/model1", "http://sbols.org/v3#source": [ { "@id": "http://virtualparts.org" } ] } ]
Using rdflib 6.0.2 (and 6.0.1) when the above file is loaded, the value of property http://sbols.org/v3#source
is http://virtualparts.org/
instead of http://virtualparts.org
. Note the trailing /
. This does not happen with other formats like 'nt11', 'xml', or 'ttl'. The issue appears to be with the json-ld parser, not the json-ld serializer.
I have written a self-contained program that demonstrates this issue:
import rdflib
print(f'Using rdflib {rdflib.version}') g = rdflib.Graph() g.add((rdflib.URIRef('https://sbolstandard.org/examples/model1'), rdflib.URIRef('http://sbols.org/v3#source'), rdflib.URIRef('http://virtualparts.org')))
def round_trip(rdf_format): print(f'-------------------- Testing {rdf_format} --------------------') data = g.serialize(format=rdf_format) # print() # print(f'Data:\n{data}') g2 = rdflib.Graph() g2.parse(data=data, format=rdf_format)
g_objects = list(g.objects())
g2_objects = list(g2.objects())
if g_objects == g2_objects:
print(f'Round trip {rdf_format} looks good')
else:
print(f'Oh no! Things are different with {rdf_format}!')
print(f'g has {g_objects}')
print(f'g2 has {g2_objects}')
round_trip('xml') round_trip('ttl') round_trip('nt11') round_trip('json-ld')
Here is the output of the the program:
$ python3 examples/jsonldbug.py
Using rdflib 6.0.2
-------------------- Testing xml --------------------
Round trip xml looks good
-------------------- Testing ttl --------------------
Round trip ttl looks good
-------------------- Testing nt11 --------------------
Round trip nt11 looks good
-------------------- Testing json-ld --------------------
Oh no! Things are different with json-ld!
g has [rdflib.term.URIRef('http://virtualparts.org')]
g2 has [rdflib.term.URIRef('http://virtualparts.org/')]