URIRef with base and fragment #1594
Replies: 1 comment
-
TL;DR - the behaviour of Incorrect>>> URIRef('string', base='http://www.w3.org/2001/XMLSchema#')
rdflib.term.URIRef(u'http://www.w3.org/2001/string') Correct>>> URIRef("#string", base="http://www.w3.org/2001/XMLSchema")
rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#string') ExplanationLess cryptically, you're “holding it wrong” --- but the lack of documentation doesn't help. The thing is, that on its own the The example you provided >>> URIRef('string', base='http://www.w3.org/2001/XMLSchema#')
rdflib.term.URIRef(u'http://www.w3.org/2001/string') is correct according to the Python documentation for >>> from urllib.parse import urljoin
>>> urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html')
'http://www.cwi.nl/%7Eguido/FAQ.html' Now what you wanted was: >>> URIRef("#string", base="http://www.w3.org/2001/XMLSchema")
rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#string') At first glance, that might seem a bit nit-picky but it's necessary because of the equivalence of a URI with and without a fragment identifier appended. Using the XSD namespace as an example, solid-namespace publishes it with a fragment identifier appended, whereas Linked Open Vocabularies doesn't. The wikipedia entry for URI_fragment notes:
Note: “a complete RDF file” - so a fragment identifier is needed to (notionally) index into the document. OTOH, trailing slashes indicate that's it's not a complete RDF file but (again, notionally) a collection of smaller ones and so the indexing is just straightforward slash-based and doesn't use, or need, a fragment identifier: >>> URIRef("deathDate", base="http://dbpedia.org/ontology/")
rdflib.term.URIRef('http://dbpedia.org/ontology/deathDate') Some more examples, just for completeness ... With fragment identifier:>>> URIRef("#type", base="http://www.w3.org/1999/02/22-rdf-syntax-ns")
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
>>> URIRef("#FunctionalProperty", base="http://www.w3.org/2002/07/owl")
rdflib.term.URIRef('http://www.w3.org/2002/07/owl#FunctionalProperty')
>>> URIRef("#string", base="http://www.w3.org/2001/XMLSchema")
rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#string') Without fragment identifier:>>> URIRef("title", base="http://purl.org/dc/terms/")
rdflib.term.URIRef('http://purl.org/dc/terms/title')
>>> URIRef("abstract", base="http://purl.org/dc/dcmitype/")
rdflib.term.URIRef('http://purl.org/dc/dcmitype/abstract') I hope this clarifies how to use |
Beta Was this translation helpful? Give feedback.
-
Base URIs that do not end in a slash have parts stripped off (for example aparent when translating sparql queries with a BASE).
I tried to find in https://tools.ietf.org/html/rfc3986#section-5.2 whether this is correct, but remain unsure. It comes from using
urlparse.urljoin()
. I tried to test this behaviour on other implementions. The virtuoso at https://dbpedia.org/sparql does not have the parts trimmed off for the following query:Beta Was this translation helpful? Give feedback.
All reactions