W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > January to March 2005

Constraints and options [was: Re: Minor Syntax issues]

From: Seaborne, Andy <andy.seaborne@hp.com>
Date: Wed, 16 Feb 2005 11:51:45 +0000
Message-ID: <421333D1.10003@hp.com>
To: Dave Beckett <dave.beckett@bristol.ac.uk>
CC: RDF Data Access Working Group <public-rdf-dawg@w3.org>
Dave,

Thanks for the corrections, I have corrected the small editorial ones in rq23 
and noted some others (or checked they were already on my "To Do" list).

One substantive issue:

> 5.2 "Constraints can be given in optional blocks"
> 
> This surprises me.  All constraints are global - this seems to imply a new  
> feature of scoped constraints.

Consider:

SELECT ?title ?price
WHERE
    ( ?book dc:title ?title )
    OPTIONAL { ( ?book x:price ?price ) AND ?price < 15 }

This adds the price information to the results only if it exists and is less 
that a certain amount.

Moving the AND clause out of the OPTIONAL does not help because the constraint 
can't remove a binding in a solution but leave the rest: this is close but 
different:

SELECT ?title ?price
WHERE
    ( ?book dc:title ?title )
    OPTIONAL { ( ?book x:price ?price ) }
    AND ! BOUND(?price) || ?price < 15


I tried several variations as below (zipped data, queries and manifest attached 
to save anyone retyping).

This isn't new - this has always been there  - I guess the language has been 
confusing.  RDQL was a much simpler case where there can be different ways of 
thinking about constraints but they come to the same thing (e.g. RDFStore's 
inline constraints).  In SPARQL, it's different.

	Andy

== Data:

@prefix x: <http://example.org/ns#> .
@prefix : <http://example.org/books#> .
@prefix dc:         <http://purl.org/dc/elements/1.1/> .

:book1 dc:title "TITLE 1" .
:book1 x:price  10 .

:book2 dc:title "TITLE 2" .
:book2 x:price  20 .

:book3 dc:title "TITLE 3" .


==== Query 1:
Constraint with the optional

PREFIX  x: <http://example.org/ns#>
PREFIX dc:  <http://purl.org/dc/elements/1.1/>

SELECT ?title ?price
WHERE
    ( ?book dc:title ?title )
    OPTIONAL { ( ?book x:price ?price ) AND ?price < 15 }

== Result 1:
---------------------
| title     | price |
=====================
| "TITLE 1" | 10    |
| "TITLE 2" |       |
| "TITLE 3" |       |
---------------------

==== Query 2:
Constraint applied to potential completed solutions
Unbound variable removes two solutions.

PREFIX  x: <http://example.org/ns#>
PREFIX dc:  <http://purl.org/dc/elements/1.1/>

SELECT ?title ?price
WHERE
    ( ?book dc:title ?title )
    OPTIONAL { ( ?book x:price ?price ) }
    AND ?price < 15

== Result 2:

---------------------
| title     | price |
=====================
| "TITLE 1" | 10    |
---------------------

==== Query 3:
If price is bound but more than 15, the solution is removed.

PREFIX  x: <http://example.org/ns#>
PREFIX dc:  <http://purl.org/dc/elements/1.1/>

SELECT ?title ?price
WHERE
    ( ?book dc:title ?title )
    OPTIONAL { ( ?book x:price ?price ) }
    AND ! BOUND(?price) || ( ?price < 15 )

== Result 3:
---------------------
| title     | price |
=====================
| "TITLE 1" | 10    |
| "TITLE 3" |       |
---------------------



Received on Wednesday, 16 February 2005 11:53:47 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:22 GMT