Issue parsing Turtle with info URI · Issue #816 · RDFLib/rdflib (original) (raw)
I am trying to read a TTL stream and parse into a graph by replacing a public URI (http://ex.org/res/
) with an internal URI (info:ns/
). I want to do this using the tools provided by RDFLib rather than writing tedious and error-prone pattern matching code.
>>> from rdflib import URIRef, Graph
INFO:rdflib:RDFLib Version: 4.2.2
>>> g1 = Graph().parse(data='<http://ex.org/res/1> a <http://auth.edu/ns#Resource> .', format='turtle')
>>> ttl1 = g1.serialize(format='turtle', base='http://ex.org/res')
>>> print(ttl1.decode())
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
</1> a <http://auth.edu/ns#Resource> .
>>> g2 = Graph().parse(data=ttl1, format='turtle', publicID=URIRef('info:ns'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/graph.py", line 1043, in parse
parser.parse(source, self, **args)
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 1870, in parse
p.loadStream(source.getByteStream())
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 434, in loadStream
return self.loadBuf(stream.read()) # Not ideal
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 440, in loadBuf
self.feed(buf)
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 466, in feed
i = self.directiveOrStatement(s, j)
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 487, in directiveOrStatement
j = self.statement(argstr, i)
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 721, in statement
argstr, i, r) # Allow literal for subject - extends RDF
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 1406, in object
j = self.subject(argstr, i, res)
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 733, in subject
return self.item(argstr, i, res)
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 829, in item
return self.path(argstr, i, res)
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 837, in path
j = self.nodeOrLiteral(argstr, i, res)
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 1431, in nodeOrLiteral
j = self.node(argstr, i, res)
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 1049, in node
j = self.uri_ref2(argstr, i, res)
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 1218, in uri_ref2
uref = join(self._baseURI, uref) # was: uripath.join
File "/home/scossu/code/lakesuperior/virtualenv/lib/python3.5/site-packages/rdflib/plugins/parsers/notation3.py", line 135, in join
"colon - with relative '%s'.") % (here, there))
ValueError: Base <info:ns> has no slash after colon - with relative '/1'.
To my knowledge, info:ns/...
is a valid URI. Is this something that conflicts with the N3 syntax, or something else?
Thanks.