[CC- public-rdf-dawg]
Dan Brickley wrote:
On Tue, Aug 25, 2009 at 2:45 PM, Lee Feigenbaum<[email protected]> wrote:
Hi Toby,
I've CCed the SPARQL WG list but also the public-sparql-dev list which in
general is better suited for "how do I..." SPARQL questions. If I'm correct
that that best suits the nature of this question, please drop
[email protected] from future messages in this thread.
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
This will bind ?date to the first of the predicates that have a value for
each ex:Item.
First in the query (textually, ie. created before issued before date,
...), or first in the data?
First in the query.
If the former - I hadn't realised OPTIONAL was ordered, if it is...
Yes, OPTIONAL is order sensitive, by virtue of being a non-commutative
binary operator (analogous to left join in SQL).
That said, there are many cases in which the placement of an OPTIONAL is
irrelevant. I believe that smarter people than me have attempted to
characterize when the order matters.
Lee
cheers,
Dan