Re: FILTER inside FILTER?

On 01/11/10 16:12, Birte Glimm wrote:
> Hi all,
> I  was just wondering whether I can have something like double
> negation/not exists within not exists, e.g., is
>    SELECT ?X WHERE { { ?x a ex:A } FILTER NOT EXISTS { FILTER NOT
> EXISTS { ?x a ex:B } } }
> a legal query?

yes.

> According to the grammar it seems to be, but from
> looking at the algebra, I can't see how I would translate that into a
> proper query algebra expression. There is still @@NOT EXISTS, so maybe
> all will be clear once that is defined, but inuitively, I would expect
> that when evaluating the innermost FILTER NOT EXISTS, I substract
> solutions from the ?x a ex:A evaluation according to the filer, but
> then it is unclear what the outer FILTER NOT EXISTS works on.
>
> E.g., my default graph has:
> ex:a1 a ex:A .
> ex:a2 a ex:A .
> ex:a2 a ex:B .
>
> For the BGP ?x a ex:A, I get mu1=(x/ex:a1) and mu2=(x/ex:a2). When I
> then evaluate FILTER NOT EXISTS { ?x a ex:B }, it remains
> mu1=(x/ex:a1), but then?

s/?X/?x/

---------
| x     |
=========
| ex:a2 |
---------

SELECT ?x WHERE
{ { ?x a ex:A }
   FILTER NOT EXISTS
       { FILTER NOT EXISTS { ?x a ex:B } }
  }

NOT EXISTS works by substituting the variables, executing the pattern 
and seeing if there are any rows.

The inner
       { FILTER NOT EXISTS { ?x a ex:B } }
is a filter on the result of the empty pattern

 > For the BGP ?x a ex:A, I get mu1=(x/ex:a1) and mu2=(x/ex:a2).

Yes.


For mu1=(x/ex:a1)

FILTER NOT EXISTS { P }
where P = { FILTER NOT EXISTS { ex:a1 a ex:B } }
which is a FILTER on the empty pattern.
{ ex:a1 a ex:B } does not exist => FILTER is true.
{ FILTER true } => one row, no bindings.

FILTER NOT EXISTS { { FILTER true } => false
==> no solution.

For mu2=(x/ex:a2):

FILTER NOT EXISTS { P }
where P = { FILTER NOT EXISTS { ex:a2 a ex:B } }
which is a FILTER on the empty pattern.
{ ex:a2 a ex:B } does exist => FILTER is false.
{ FILTER false } => no rows

FILTER NOT EXISTS { { FILTER false } => true
==> mu2=(x/ex:a2)

 Andy

>
> Maybe I am overlooking something here or maybe the query is not legal?
>
> Birte
>

Received on Monday, 1 November 2010 21:00:35 UTC