W3C home > Mailing lists > Public > public-sparql-dev@w3.org > October to December 2010

boolean shorthand for common optional/union patterns

From: Danny Ayers <danny.ayers@gmail.com>
Date: Mon, 6 Dec 2010 17:43:37 +0100
Message-ID: <AANLkTinyz1f1H=T0HcuWZguBeeEBRekuhARE=Oy1Y0Pf@mail.gmail.com>
To: public-sparql-dev@w3.org
Seems like it's often desirable to query over synonyms or near
synonyms, e.g. where resourceA owl:sameAs resourceB, leading to
something like:

SELECT ... WHERE {

   OPTIONAL { pattern(<resourceA>) }
   OPTIONAL { pattern(<resourceB>) }

}

- where each pattern block is the same except for the different resource(s).

So (with apologies if I've overlooked a really obvious alternative)
why not sugar this up a bit and shorten it to something like:

SELECT ... WHERE {

   pattern(<resourceA> || <resourceB>)

}

Ok, a proper example -

SELECT ?label
WHERE  {
   ?x (rdfs:label || dc:title)  ?label .
}

would produce exactly the same results as:

SELECT ?label
WHERE  {
   OPTIONAL { ?x rdfs:label  ?label }
   OPTIONAL { ?x  dc:title  ?label }
}

This example only saves a few characters, but with richer queries it
may not only reduce the typing but also make them easier to read &
maintain.

I've included (braces) above, but it looks pretty unambiguous and I
suspect wouldn't add much to a parser's complexity with or without
braces - it's a kinda macro, as the song goes.

I've not had chance to play with this, but at first glance at least it
seems like the && and ! operators could be used in a similar fashion
(abbreviating unions and a certain shape of filter, I think...).

Cheers,
Danny.
Received on Monday, 6 December 2010 16:44:13 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 6 December 2010 16:44:14 GMT