-
Notifications
You must be signed in to change notification settings - Fork 581
Open
Labels
SPARQLbugSomething isn't workingSomething isn't workingreconfirmThis issue may be solved already and should be reconfirmed.This issue may be solved already and should be reconfirmed.
Description
Context. I tried to subclass rdflib.URIRef and use it my code because I wanted to add additional functionality to it.
Expectations. I expected a subclass of URIRef to work exactly like URIRef itself works.
Reality. However, it appeared that SPARQL querying will not properly work in that case. Here is a full fledged example.
import rdflib
from rdflib import Graph, FOAF
class IRI(rdflib.URIRef):
"""Internationalized Resource Identifier."""
def __repr__(self):
"""Format IRI."""
return f'<{self.toPython()}>'
def test_uriref_subclass():
graph = Graph()
graph.add((
IRI('https://example.com/Alice'),
IRI(FOAF.knows),
IRI('https://example.com/Bob'),
))
bindings = graph.query(
'SELECT * WHERE { ?s <http://xmlns.com/foaf/0.1/knows> ?o . }',
).bindings
# Here we see that bindings are empty: nothing was found.
assert not bindings(This code should be runnable as-is.)
Since we added a triple to graph, I expected to find that triple via a SPARQL query but to no avail because FOAF.knows is saved as a IRI, not as a URIRef.
This is a non-standard pattern of usage, but would be great to see if anyone had circumvented such a problem.
rchateauneu
Metadata
Metadata
Assignees
Labels
SPARQLbugSomething isn't workingSomething isn't workingreconfirmThis issue may be solved already and should be reconfirmed.This issue may be solved already and should be reconfirmed.