Re: Common variables across multiple optional blocks [OK?]

Ian Davis wrote:
> Hi all,
> 
> It seems that the following query has indeterminate solutions
> 
> PREFIX foaf: <http://xmlns.com/foaf/0.1/>
> SELECT ?name ?page
> WHERE  {
>    ?x foaf:name  ?name .
> 
>    OPTIONAL { ?x foaf:homepage ?page . }
>    OPTIONAL { ?x foaf:workplaceHomepage ?page . }
> }
> 
> Text in an earlier draft forbade this situation:
> 
> http://www.w3.org/TR/2005/WD-rdf-sparql-query-20050217/#OptionalRule
> 
> "A variable can not be used in two optional blocks where the outermost 
> mention (shallowest occurrence in the tree for each occurrence) of the 
> two uses is not the same block."
> 
> This was moved to a new section on query execution order:
> 
> http://www.w3.org/TR/2005/WD-rdf-sparql-query-20050419/#queryExecutionOrder
> 
> "Optional-2... informally, this rule states that there can't be two 
> optionals with a common variable, if that variable does not occur in a 
> basic graph pattern as well."
> 
> This entire section was removed from the July draft.
> 
> I think that this rule needs to be reinstated.
> 
> For more information and background on this please see chat leading up 
> to http://chatlogs.planetrdf.com/swig/2006-01-17#T20-51-16
> 
> Cheers,
> 
> Ian
> 

The July draft was the Last Call version.

The OPTIONAL operator is defined as a binary operator and it is 
left-associative (the latter has been added since as it was unclear as someone 
pointed out).

So
  {
     ?x foaf:name  ?name .
     OPTIONAL { ?x foaf:homepage ?page . }
     OPTIONAL { ?x foaf:workplaceHomepage ?page . }
  }

is (adding some braces):
  {
     { {  ?x foaf:name  ?name . }
          OPTIONAL { ?x foaf:homepage ?page . }
       }
       OPTIONAL { ?x foaf:workplaceHomepage ?page . }
  }

that is, the second optional will operate on the matching of the of the first.

Because the situation is well defined by the definition of OPTIONAL in the 
last call document, the working group removed the text you quoted.

In your example, the first OPTIONAL will match, giving a value to ?page.  The 
second optional is then fully grounded (and does not match on your data).

http://pastebin.com/511241


I hope this responds to your comment.  It is does, please let us know (if you 
send a reply with [CLOSED] on the subject line, scripts will sort it out for us).

	Thanks,
	Andy

Received on Wednesday, 18 January 2006 10:39:35 UTC