fix: allow registered prefix use and namespaces which are URIs closes #632 by satra · Pull Request #660 · RDFLib/rdflib (original) (raw)

@gromgull - let me know if we should move the discussion to #649, but i'll respond here for now!

this hack does fix #632 as the cache would contain the full URI.

i completely agree that this is a hack and should be replaced with sth better. however, if you do move the triples and bind the namespace there, you would regenerate the cache. if you simply copied the namespaces internally without going through a bind then you would not have the new cache.

the key here is that the cache generation happens on bind, and that's the point. the namespace prefix is a serialization concept not an RDF concept. RDF simply says URIs. turtle/trig on the other hand allows prefix-es.

therefore, if i explicitly bind a prefix to a valid string, rdflib shouldn't parse it down to a prefix, URI, and part. so both of the following prefixes would be completely valid:

@prefix ex: http://example.org/ . @prefix ex_foo: http://example.org/#foo

the problem right now is that the prefix generator in rdflib takes a decision that the prefix cannot be: <http://example.org/#foo> even though it's been instructed to by the user and is in full compliance with turtle specs.

import rdflib as rl g = rl.Graph() g.bind('ex', 'http://example.org/#foo') g.compute_qname('http://example.org/#foo')

returns

Out[8]: ('ns1', rdflib.term.URIRef('http://example.org/#'), 'foo')

whereas it should have returned:

Out[8]: ('ex', rdflib.term.URIRef('http://example.org/#foo'), '')

i'm happy to propose a non-hacked solution if there is agreement that rdflib should keep the prefix as determined by the bind call