W3C home > Mailing lists > Public > public-rdf-dawg-comments@w3.org > August 2009

Re: SPARQL Query Problem - perhaps solvable in 1.1?

From: Toby Inkster <tai@g5n.co.uk>
Date: Tue, 25 Aug 2009 14:00:46 +0100
To: Lee Feigenbaum <lee@thefigtrees.net>
Cc: public-rdf-dawg-comments@w3.org, public-sparql-dev@w3.org
Message-Id: <1251205246.3069.77.camel@ophelia2.g5n.co.uk>
On Tue, 2009-08-25 at 08:45 -0400, Lee Feigenbaum wrote:

> If I understand you correctly, the pattern you're looking for is that 
> you have a prioritized list of predicates that you want to use for a 
> particular value, in this case date. The "canonical" way to do this in 
> SPARQL (or, at least, what I've always done and seen done) is to use a 
> series of OPTIONAL clauses that all bind to the same variable:
> 
> SELECT ?date {
>     ?item a ex:Item .
>     OPTIONAL { ?item dct:created ?date }
>     OPTIONAL { ?item dct:issued ?date }
>     OPTIONAL { ?item dct:date ?date }
>     OPTIONAL { ?item dc:date ?date }
> } ORDER BY ?date

Wow! That actually seems to work! How did I not spot this?

It means I lose out on knowing which of the predicates worked, so I
can't perfectly reconstruct the original triples in my application. But
that, I think I can live with.

Nevertheless I think a COALESCE function would still be a useful
addition to SPARQL 1.1.

-- 
Toby A Inkster
<mailto:mail@tobyinkster.co.uk>
<http://tobyinkster.co.uk>
Received on Tuesday, 25 August 2009 13:01:43 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 25 August 2009 13:01:43 GMT