-
Notifications
You must be signed in to change notification settings - Fork 574
Using FROM and FROM NAMED on ConjunctiveGraph behaves not standard conform #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For a while, I thought this might be related to the identifier-as-context changes but now I realise that it's unrelated. fwiw, test included: import rdflib.plugins.sparql
from rdflib import ConjunctiveGraph
def test_issue811():
data = """
<urn:a> <urn:a> <urn:a> <urn:a> .
<urn:b> <urn:b> <urn:b> <urn:b> .
<urn:c> <urn:c> <urn:c> <urn:c> .
"""
rdflib.plugins.sparql.SPARQL_DEFAULT_GRAPH_UNION = False
rdflib.plugins.sparql.SPARQL_LOAD_GRAPHS = False
graph = ConjunctiveGraph()
graph.parse(data=data, format="nquads")
assert len(graph) == 3
assert len(graph.query("SELECT * {?s ?p ?o .}")) == 0
# Set default graph as UNION, CORRECT result
rdflib.plugins.sparql.SPARQL_DEFAULT_GRAPH_UNION = True
assert len(graph.query("SELECT * {?s ?p ?o .}")) == 3
# Use FROM to specify <urn:b> as the default graph
# Set default graph as UNION, INCORRECT result
rdflib.plugins.sparql.SPARQL_DEFAULT_GRAPH_UNION = True
assert (
len(graph.query("SELECT * FROM <urn:b> {?s ?p ?o}")) == 3
), "should be 1 triple"
# Set default graph as NON-UNION, CORRECT result
rdflib.plugins.sparql.SPARQL_DEFAULT_GRAPH_UNION = False
assert (
len(graph.query("SELECT * FROM <urn:b> {?s ?p ?o}")) == 1
), "should be 1 triple"
# Use FROM NAMED to specify <urn:b> as target graph
# Set default graph as UNION, INCORRECT result
rdflib.plugins.sparql.SPARQL_DEFAULT_GRAPH_UNION = True
assert (
len(graph.query("SELECT * FROM NAMED <urn:b> {?s ?p ?o}")) == 3
), "should be 1 triple"
# Set default graph as NON-UNION, CORRECT result
rdflib.plugins.sparql.SPARQL_DEFAULT_GRAPH_UNION = False
assert (
len(graph.query("SELECT * FROM NAMED <urn:b> {?s ?p ?o}")) == 1
), "should be 1 triple" |
will add with xfail if I have time |
Since the issue still doesn't have a fix, I made one: And also: In my understanding of the w3c spec, if we define a |
I want to use
FROM
andFROM NAMED
in a SPARQL query to select the default graph resp. named graphs to execute the query on. But the RDFlib implementation does not act as it is described in the SPARQL 1.1 specification especially the section "13.2 Specifying RDF Datasets" (https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#specifyingDataset)To demonstrate this behavior, I've created an MWE:
Running this code behaves as expected, while I will show derived examples in the following, by altering Line A and Line B:
1. Replacing the Default Graph
<urn:b> <urn:b> <urn:b>
as result2. Specifying a Named Graph but Querying the Default Gaph
3. Specifying a Named Graph
<urn:b> <urn:b> <urn:b> <urn:b>
as resultNAMED GRAPH
to specify a named graph to query.Because I think all of these three cases are related to each other I've put them into one issue, but sure they could also be split into three issues.
The text was updated successfully, but these errors were encountered: