Re: Visibility of variables in nested Group(OrUnion)GraphPatterns

good afternoon;

> On 2015-08-27, at 13:27, Michael Schmidt <ms@metaphacts.com> wrote:
> 
> Dear community,
> 
> I’ve repeatedly observed inconsistent behaviour across SPARQL engines when it comes to the visibility of variables in nested groups (or in UNIONs). Let me illustrate the issues through a couple of queries, to be executed over a simple dataset consisting of the two triples:
> 
> <http://example.com/Alice> a <http://example.com/Person> .
> <http://example.com/Flipper> a <http://example.com/Animal> .
> 
> 
the most transparent bases for interpretation are the algebra expressions.
sparql.org’s are included below.


> 1a.) Visibility of FILTERs
> 
> SELECT ?s ?type WHERE { 
>   BIND(<http://example.com/Person> AS ?type)
>   { ?s ?p ?o FILTER(?o=?type) }
> }

  1 (base <http://example/base/>
  2   (project (?s ?type)
  3     (join
  4       (extend ((?type <http://example.com/Person>))
  5         (table unit))
  6       (filter (= ?o ?type)
  7         (bgp (triple ?s ?p ?o))))))

?type’s scope includes the join and it’s dominant forms, but does not not include the filter.

> 
> As far as I understand the spec, the variable ?type is not visible in the inner subgroup, so it is unbound when evaluating the FILTER. As a consequence, this query should return the empty result. Is this correct?
> 
> 
> 1b.) A slight variant of this example is where we do not consider a GroupGraphPattern but a GroupOrUnionGraphPattern:
> 
> SELECT ?s ?type WHERE { 
>   BIND(<http://example.com/Person> AS ?type)
>   { ?s ?p ?o FILTER(?o=?type) }
>  UNION
>  { ?s ?p ?o FILTER(?o!=?type) }
> }

  1 (base <http://example/base/>
  2   (project (?s ?type)
  3     (join
  4       (extend ((?type <http://example.com/Person>))
  5         (table unit))
  6       (union
  7         (filter (= ?o ?type)
  8           (bgp (triple ?s ?p ?o)))
  9         (filter (!= ?o ?type)
 10           (bgp (triple ?s ?p ?o)))))))

the same is true for this expression.

> 
> Again, variable ?type should not be visible in any part of the UNION, so both filters evaluate to error and the result is empty again. Is this correct?
> 
> 
> 2a.) Let’s now consider examples where we reuse variables from outside in BIND expressions rather than FILTERs:
> 
> SELECT ?s ?type WHERE { 
>   BIND("http://example.com/" AS ?typeBase)
>   {
>     BIND(URI(CONCAT(?typeBase,"Person")) AS ?type)
>    ?s ?p ?o
>    FILTER(?o=?type)
>   }
> }

  1 (base <http://example/base/>
  2   (project (?s ?type)
  3     (join
  4       (extend ((?typeBase "http://example.com/"))
  5         (table unit))
  6       (filter (= ?o ?type)
  7         (join
  8           (extend ((?type (uri (concat ?typeBase "Person"))))
  9             (table unit))
 10           (bgp (triple ?s ?p ?o)))))))

in this case, the second filter in within the scope of the ?type binding, but that binding's contributing ?typeBase reference is outside of the scope of the respective binding

> 
> The query tries to bind variable ?type in the nested group based on variable ?typeBase, which is defined outside. In my understanding, this outer variable (?typeBase) should not be visible when executing the inner BIND, so this query would return the empty result?
> 
> 
> 2b.) A slight variant of the previous one with a GroupOrUnionGraphPattern:
> 
> 
> SELECT ?s ?type WHERE { 
>   BIND("http://example.com/" AS ?typeBase)
>   {
>     BIND(URI(CONCAT(?typeBase,"Person")) AS ?type)
>     ?s ?p ?o
>     FILTER(?o=?type)
>   }
>   UNION
>   {
>     BIND(URI(CONCAT(?typeBase,"Animal")) AS ?type)
>     ?s ?p ?o
>     FILTER(?o=?type)
>   }
> }
> 

  1 (base <http://example/base/>
  2   (project (?s ?type)
  3     (join
  4       (extend ((?typeBase "http://example.com/"))
  5         (table unit))
  6       (union
  7         (filter (= ?o ?type)
  8           (join
  9             (extend ((?type (uri (concat ?typeBase "Person"))))
 10               (table unit))
 11             (bgp (triple ?s ?p ?o))))
 12         (filter (= ?o ?type)
 13           (join
 14             (extend ((?type (uri (concat ?typeBase "Animal"))))
 15               (table unit))
 16             (bgp (triple ?s ?p ?o))))))))

> Also here I’d expect the empty result.

as would appear correct from the algebra expression.

best regards, from berlin,
---
james anderson | james@dydra.com | http://dydra.com

Received on Sunday, 30 August 2015 11:57:17 UTC