- From: Seaborne, Andy <andy.seaborne@hp.com>
- Date: Wed, 16 Feb 2005 11:51:45 +0000
- To: Dave Beckett <dave.beckett@bristol.ac.uk>
- CC: RDF Data Access Working Group <public-rdf-dawg@w3.org>
- Message-ID: <421333D1.10003@hp.com>
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" | |
---------------------
Attachments
- application/x-zip-compressed attachment: expr1.zip
Received on Wednesday, 16 February 2005 11:53:47 UTC