original) (raw)
util.from_n3() is broken wrt. Literals with datatypes · Issue #502 · RDFLib/rdflib (In [1]: import rdflib INFO:rdflib:RDFLib Version: 4.2.1-dev
In [2]: rdflib.util.from_n3('"42"^^http://www.w3.org/2001/XMLSchema#integer') WARNING:rdflib.term:http://www.w3.org/2001/XMLSchema#integer does not look like a valid URI, trying to serialize this will break. Out[2]: rdflib.term.Literal(u'42', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))
problem here is that the <
is passed into URIRef()
as part of the URI.
In [3]: rdflib.util.from_n3('"42"^^xsd:integer') Out[3]: rdflib.term.Literal(u'42', datatype=rdflib.term.URIRef(u'xsd:integer'))
problem is that standard xsd datatypes aren't resolved correctly but instead passed into URIRef()
as is.
In [4]: rdflib.util.from_n3('"42"^^http://www.w3.org/2001/XMLSchema#integer') Out[4]: rdflib.term.Literal(u'42', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))
In [5]: rdflib.Literal(42) == rdflib.util.from_n3('"42"^^http://www.w3.org/2001/XMLSchema#integer') Out[5]: True
this is actually invalid n3 but the only thing that returns the expected Literal
More fun (round-tripping):
In [6]: rdflib.util.from_n3(rdflib.Literal(42).n3()).n3() WARNING:rdflib.term:http://www.w3.org/2001/XMLSchema#integer does not look like a valid URI, trying to serialize this will break. Out[6]: u'"42"^^<http://www.w3.org/2001/XMLSchema#integer>'