W3C home > Mailing lists > Public > public-rdf-dawg-comments@w3.org > April 2006

Re: Ambiguities in optional scope

From: Seaborne, Andy <andy.seaborne@hp.com>
Date: Thu, 20 Apr 2006 12:56:46 +0100
Message-ID: <444776FE.3070605@hp.com>
To: Jorge Pérez <jperez@utalca.cl>
CC: public-rdf-dawg-comments@w3.org



Jorge Pérez wrote:
> Hi! I think that the following query is problematic too. I tried it in 
> SPARQLer and gave me strange results and in the SPARQL last draft I cannot 
> find a precise answer:
> 
> The data is:
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> @prefix : <http://ing.utalca.cl/~jperez/research/rdf/> .
> 
> _:b1 :titlename  "book1" . 
> _:b1 :authorname "author1" .
> _:b1 :year       "2006" .
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 
> The query:
> 
> PREFIX : <http://ing.utalca.cl/~jperez/research/rdf/>
> SELECT *
> FROM :sample2.rdf
> WHERE {
>   ?B :titlename ?N .
>   ?B :year ?Y .
>   OPTIONAL { ?B :authorname ?N }
> }
> 
> What is the answer? Again at least two possibilities according to the "scope" 
> of optional
> 
> 1) B=_:b1, N="book1", if one assume that the optional "is applied to" the two 
> triple patterns.
> 2) nothing, if one assume that the optonal "is applied to" the second triple 
> pattern.
> 
> The ambiguitie starts again in the formal definition of optional, it 
> reads "...the second pattern modifies pattern solutions of the first 
> pattern..." but here there is no clear what the "first pattern" is. SPARQLer 
> gave me solution 1) but I cannot find a rule in the draft that validate this 
> behavior. If one consider the following query (I put just the WHERE part)
> 
> WHERE {
>   ?B :year ?Y .
>   OPTIONAL { ?B :authorname ?N }
>   ?B :titlename ?N .
> }
> 
> the solution is not clear... one may assume here that the optional "is applied 
> to" just the triple pattern above but again there is no formal validation of 
> this in the draft. Here the left associativity rule of the optional keyword 
> included in the last draft do not applied because it states that optional is 
> left associative considering other optional patterns but nothing about triple 
> patters. In this case SPARQLer gave me solution 2).
> 
> How can one solve the problem? 
> * One posibility is to add a complete set of associative rules: "." keyword is 
> left associative, "optional" keyword is left associative, etc. from my point 
> of view it may make the specification less readable.
> * Other posibility is to think that each complex graph pattern (group graph 
> pattern) has a "mandatory part" and several "optional parts". A solution must 
> match the complete manatory part, and optional parts only add "information" to 
> the solution of the mandatory part if the information exists. The evaluation 
> of optional parts is made resursively in the same way.
> * Other?
> 
> - Jorge

Jorge,

The translation from syntax to conceptual query is given by the SPARQL grammar 
in the document.

The key rules are
[20]    	GraphPattern
[21]    	FilteredBasicGraphPattern  	
[19]    	GroupGraphPattern
[23]    	GraphPatternNotTriples


Rule [20] is the top level graph pattern rule.

Rule [21] causes sequences of triple patterns to be gathered together.  This 
rule is the only path through the grammar to have triple patterns in a query. 
  It is a basic graph pattern (BGP) with addition value constraints.  Being an 
inner rules, it gives triples patterns, and '.' a high precedence.

Rule [19] is the rule for {} blocks.

Rule [23] enumerates the various pattern types, except for basic graph 
pattern, and each pattern type uses rule [19].

Taking a query

 > PREFIX : <http://ing.utalca.cl/~jperez/research/rdf/>
 > SELECT *
 > FROM :sample2.rdf
 > WHERE {
 >   ?B :titlename ?N .
 >   ?B :year ?Y .
 >   OPTIONAL { ?B :authorname ?N }
 > }

then
   ?B :titlename ?N .
   ?B :year ?Y .
form a basic graph pattern by rule [19] and optional combines that BGP with 
the "{ ?B :authorname ?N }". to form a single graph pattern.  The outer group 
  of the WHERE has one element.

But this:
 > WHERE {
 >   ?B :year ?Y .
 >   OPTIONAL { ?B :authorname ?N }
 >   ?B :titlename ?N .
 > }

is a different query - it has a different structure in the grammar (it's a 
optional of a BGP (?B :year ?Y) and BGP (?B :authorname ?N) in a group with 
BGP (?B :titlename ?N).  The outer group of the WHERE has two elements.

Your "possibility one" is already there - it's the grammar which gives the 
mapping from syntax to conceptual form.

	Andy
Received on Thursday, 20 April 2006 11:57:08 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:14:50 GMT