Empty optional

10 views
Skip to first unread message

srfi...@gmail.com

unread,
Jan 2, 2019, 8:04:26 PM1/2/19
to rdflib-dev
Dear all,

We are having a little problem with left-empty optional queries, which I believe might be a little bug in how rdflib is dealing with query results with empty bindings.

Consider an EMPTY graph and execute the following query

ASK { OPTIONAL {?x ?y ?z} }

It yields true, as other SPARQL engines. However, the query

SELECT * { OPTIONAL {?x ?y ?z} }

while yielding a SPARQLResult with one binding (len=1), its generator yields no ResultRow. Other engines return a single row, with all the projected variables set to None.

Is this the correct behaviour? If not, I believe the problem is in file

rdflib/query.py

in the code

if self._genbindings:
for b in self._genbindings:
if b: # don't add a result row in case of empty binding {}
self._bindings.append(b)
yield ResultRow(b, self.vars)
self._genbindings = None
else:
for b in self._bindings:
if b: # don't add a result row in case of empty binding {}
yield ResultRow(b, self.vars)

Both `if b:`are blocking the empty binding to appear in the result.

Some more discussion on this topic can be found in:

https://stackoverflow.com/questions/25131365/sparql-optional-query

at the end of the first answer.

best regards and thanks for the this great tool,
Sandro R. Fiorini

Reply all
Reply to author
Forward
0 new messages