You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Olivier Dameron <ol...@univ-rennes1.fr> on 2021/05/03 15:43:07 UTC

jena4: negation and filter

Dear jena users,
    I tried to replicate the negation examples from 
https://www.w3.org/TR/sparql11-query/#idp899488 (section 8.3.3 Examples: 
Inner FILTERs).
I got [(a, 1), (b, 3.0)] for both versions of the query whereas I 
expected to get only [(b, 3.0)] with the FILTER NOT EXISTS.

Same result with jena-3.17
Rdflib returns the same results as the W3C page.

Am I missing something?
Thank you
olivier


DATA:
-----
@prefix : <http://example.com/> .

:a :p :v1 .
:a :q :v1 .
:a :q :v2 .

:b :p :v3 .
:b :q :v4 .
:b :q :v5 .



QUERY 1 (expected: [(b, 3.0)] ; returned: [(a, 1), (b, 3.0)]):
--------------------------------------------------------------
PREFIX : <http://example.com/>

SELECT *
WHERE {
   ?x :p ?n .
   FILTER NOT EXISTS {
     ?x :q ?m .
     FILTER(?n = ?m)
   }
}


QUERY 2 (correctly returned [(a, 1), (b, 3.0)]):
------------------------------------------------
PREFIX : <http://example.com/>

SELECT *
WHERE {
   ?x :p ?n .
   MINUS {
     ?x :q ?m .
     FILTER(?n = ?m)
   }
}

Re: [SOLVED] jena4: negation and filter

Posted by Olivier Dameron <ol...@univ-rennes1.fr>.
On 5/3/21 7:01 PM, Andy Seaborne wrote:
> https://issues.apache.org/jira/browse/JENA-1963
> 
> Try
> 
> sparql --strict
> sparql --engine=ref
> sparql --optimize=off
> 
> The optimization rule that sees "FILTER(?n = ?m)" and tries to make it a 
> join goes wrong because of the interaction with substitution.

yes, this solves the issue

> 
> BTW:
> https://afs.github.io/substitute.html
> 
> lists several problems with NOT EXISTS and gives a solution.
> 
> The solution would also work for parameterized queries if the 
> scope-renaming is omitted.

ah, thank you for the pointer!
olivier

Re: jena4: negation and filter

Posted by Andy Seaborne <an...@apache.org>.
https://issues.apache.org/jira/browse/JENA-1963

Try

sparql --strict
sparql --engine=ref
sparql --optimize=off

The optimization rule that sees "FILTER(?n = ?m)" and tries to make it a 
join goes wrong because of the interaction with substitution.

BTW:
https://afs.github.io/substitute.html

lists several problems with NOT EXISTS and gives a solution.

The solution would also work for parameterized queries if the 
scope-renaming is omitted.

     Andy

On 03/05/2021 16:43, Olivier Dameron wrote:
> Dear jena users,
>     I tried to replicate the negation examples from 
> https://www.w3.org/TR/sparql11-query/#idp899488 (section 8.3.3 Examples: 
> Inner FILTERs).
> I got [(a, 1), (b, 3.0)] for both versions of the query whereas I 
> expected to get only [(b, 3.0)] with the FILTER NOT EXISTS.
> 
> Same result with jena-3.17
> Rdflib returns the same results as the W3C page.
> 
> Am I missing something?
> Thank you
> olivier
> 
> 
> DATA:
> -----
> @prefix : <http://example.com/> .
> 
> :a :p :v1 .
> :a :q :v1 .
> :a :q :v2 .
> 
> :b :p :v3 .
> :b :q :v4 .
> :b :q :v5 .
> 
> 
> 
> QUERY 1 (expected: [(b, 3.0)] ; returned: [(a, 1), (b, 3.0)]):
> --------------------------------------------------------------
> PREFIX : <http://example.com/>
> 
> SELECT *
> WHERE {
>    ?x :p ?n .
>    FILTER NOT EXISTS {
>      ?x :q ?m .
>      FILTER(?n = ?m)
>    }
> }
> 
> 
> QUERY 2 (correctly returned [(a, 1), (b, 3.0)]):
> ------------------------------------------------
> PREFIX : <http://example.com/>
> 
> SELECT *
> WHERE {
>    ?x :p ?n .
>    MINUS {
>      ?x :q ?m .
>      FILTER(?n = ?m)
>    }
> }