Visibility of variables in nested Group(OrUnion)GraphPatterns

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 <http://example.com/Alice>> a <http://example.com/ <http://example.com/>Person> .
<http://example.com/Flipper <http://example.com/Flipper>> a <http://example.com/Animal <http://example.com/Animal>> .


1a.) Visibility of FILTERs

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

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 <http://example.com/Person>> AS ?type)
  { ?s ?p ?o FILTER(?o=?type) }
 UNION
 { ?s ?p ?o FILTER(?o!=?type) }
}

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/ <http://example.com/>" AS ?typeBase)
  {
    BIND(URI(CONCAT(?typeBase,"Person")) AS ?type)
   ?s ?p ?o
   FILTER(?o=?type)
  }
}

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/ <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)
  }
}

Also here I’d expect the empty result.

Any thoughts, comments/clarifications would be highly appreciated.

Best,
Michael


—

Dr. Michael Schmidt
CTO
 
T +49 6227 6989965
M +49 177 388 5936
ms@metaphacts.com <mailto:ms@metaphacts.com>
http://www.metaphacts.com <http://www.metaphacts.com/>
 
metaphacts GmbH
Industriestraße 41
69190 Walldorf, Germany

Managing Director: Dr. Peter Haase
Company Register: Mannheim, HRB 720635

 <http://smartdata2015.dataversity.net/>
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

Received on Sunday, 30 August 2015 10:20:18 UTC