Problem with nested FILTER NOT EXISTS statements · Issue #709 · RDFLib/rdflib (original) (raw)

The following query:

PREFIX ex: <http://www.example.de#>
SELECT ?a ?b WHERE {
 ?a ex:rel ?b
 FILTER NOT EXISTS {
  ?a ex:rel ?b.
  FILTER NOT EXISTS {?c ex:rel2 ?b.}
 }
}

should not deliver any results on this single triple (because it lacks a triple binding for ?c ex:rel2 ?b).:

@prefix ex: <http://www.example.de#>.
ex:a ex:rel ex:b.

In contrast, however, it should deliver results on the complete set of triples:

@prefix ex: <http://www.example.de#>.
ex:a ex:rel ex:b.
ex:c ex:rel2 ex:b.

The problem is that rdflib (also the new 4.2.2 version which fixed a similar issue
#615 ) in my test delivers a result in both cases. It seems to me that the two nested FILTER statements are not evaluated correctly:

data loaded
Triples: 1
(rdflib.term.URIRef(u'http://www.example.de#a'), rdflib.term.URIRef(u'http://www.example.de#rel'), rdflib.term.URIRef(u'http://www.example.de#b'))
--------------------------------------------------------------------------------
PREFIX ex: <http://www.example.de#>

SELECT ?a ?b WHERE {
 ?a ex:rel ?b
 FILTER NOT EXISTS {
 ?a ex:rel ?b.
  FILTER NOT EXISTS {?c ex:rel2 ?b.}
 }
}
OUTPUT:
number of results:1
(rdflib.term.URIRef(u'http://www.example.de#a'), rdflib.term.URIRef(u'http://www.example.de#b'))

Nested filter statements are very important for checking completeness of a dataset. Is there a way to fix this?

simon