Parameterized queries with optional graph patterns return invalid bindings. For instance, we will give two parameters in a query string:
%3Flabel="Barack Obama"@en
%3Ftype=<http://dbpedia.org/ontology/Person>
The SPARQL query:
SELECT ?res WHERE
{
res rdfs:label ?label ;
rdf:type ?type .
}
LIMIT 10
has no optional graph patterns and the corresponding query string
http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org&?label="Barack Obama"@en&?type=<http://dbpedia.org/ontology/Person>&query=SELECT ?res WHERE { ?res rdfs:label ?label ; rdf:type ?type . } LIMIT 10
returns a valid binding for "res":
http://dbpedia.org/resource/Barack_Obama
Including an optional graph pattern into the latter query
SELECT ?res WHERE
{
?res rdfs:label ?label ;
rdf:type ?type .
OPTIONAL { ?res dbpedia-owl:thumbnail ?thumbnail . }
}
LIMIT 10
with the corresponding query string
http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org&?label="Barack Obama"@en&?type=<http://dbpedia.org/ontology/Person>&query=SELECT ?res WHERE { ?res rdfs:label ?label ; rdf:type ?type . OPTIONAL { ?res dbpedia-owl:thumbnail ?thumbnail . } } LIMIT 10
returns a list of invalid bindings for "res":
http://dbpedia.org/resource/April
http://dbpedia.org/resource/Underwater_archaeology
http://dbpedia.org/resource/Sidereal_year
http://dbpedia.org/resource/Sidereal_year
http://dbpedia.org/resource/Arcturus
http://dbpedia.org/resource/Arcturus
http://dbpedia.org/resource/Arcturus
http://dbpedia.org/resource/Arcturus
http://dbpedia.org/resource/Arcturus
http://dbpedia.org/resource/Arcturus
The same query without the OPTIONAL keyword
SELECT ?res WHERE
{
?res rdfs:label ?label ;
rdf:type ?type .
?res dbpedia-owl:thumbnail ?thumbnail .
}
LIMIT 10
with the corresponding query string
http://dbpedia.org/sparql?default-graph-uri=http://dbpedia.org&?label="Barack Obama"@en&?type=<http://dbpedia.org/ontology/Person>&query=SELECT ?res WHERE { ?res rdfs:label ?label ; rdf:type ?type . ?res dbpedia-owl:thumbnail ?thumbnail . } LIMIT 10
works properly.