rdflib
rdflib copied to clipboard
SPARQL queries don't work for Datasets
Hi, I tried to create a Dataset and query it with SPARQL, however I had no success. I retraced my steps to the SPARQL query example, which worked, however when I changed the container from Graph to Dataset, it stopped working. Curiously, it seems to work just fine with ConjunctiveGraph. My code looks like this:
from rdflib.graph import ConjunctiveGraph, Dataset, Graph
foaf="""[content of examples/foaf.n3]"""
#ds = Graph()
#ds = ConjunctiveGraph()
ds = Dataset()
ds.parse(data=foaf, format="n3")
for row in ds.query("SELECT ?s WHERE { [] foaf:knows ?s .}"):
print(row)
I looked through open issues, and this one seems the most similar, but I don't think it is related, because when I parse it with Dataset, I can enumerate it and see that the data was in fact loaded (not sure if correctly, though).
Ah, interesting: When using Datasets, using GRAPH clause seems to be mandatory, for some reason 🤔
When I use the following query, it prints everything from both ConjunctiveGraph and Dataset:
query_string = """
SELECT ?s ?p ?o ?g
WHERE {
GRAPH ?g { ?s ?p ?o }
}
"""
Isn't this because of #2375? Default graph pattern doesn't match anything because a label has been added to it?
Isn't this because of #2375? Default graph pattern doesn't match anything because a label has been added to it?
I think you are right, but I'm not 100% sure.