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

Re: How to query items of a Sequence ?

From: Paul Gearon <gearon@ieee.org>
Date: Thu, 5 Nov 2009 16:00:00 -0500
Message-ID: <a25ac1f0911051300l4a1d2bd2wccd9552c6e17d934@mail.gmail.com>
To: Etienne Morency <etienne.morency@gmail.com>
Cc: OWL Dev <public-owl-dev@w3.org>
Doh! I've been caught up in function extensions recently, and totally
forgot that this can be done with base SPARQL. See below...

On Thu, Nov 5, 2009 at 3:00 PM, Paul Gearon <gearon@ieee.org> wrote:
> If you don't have an entailment regime, then you can also try to
> filter by the structure of the predicate, but you need function
> extensions if your triplestore to handle that. For instance, on many
> triplestores you could do:
>
> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> SELECT ?sequence ?predicate ?element
> WHERE {
>  ?sequence rdf:type rdf:Seq .
>  ?sequence ?predicate ?element .
>  FILTER fn:starts-with( str(?predicate),
> "http://www.w3.org/1999/02/22-rdf-syntax-ns#_")
> }
>
> The problem with this approach is that not every SPARQL endpoint
> handles this function (yet), or they have similar though differently
> named functions. Also, doing these string comparisons could get
> expensive if you had a lot of data to return.

The better approach is to use regex.

FILTER regex(str(?predicate),
      "^http://www.w3.org/1999/02/22-rdf-syntax-ns#_\d+$")

This has the added advantage of ensuring that only numbers are used at
the end of the URI (this should be the case, but it's conceivable that
someone could write bad URIs). Thanks to Andy Seaborne for pointing
out my shortcomings.  :-)

Regards,
Paul Gearon
Received on Thursday, 5 November 2009 21:00:37 GMT

This archive was generated by hypermail 2.3.1 : Wednesday, 27 March 2013 09:32:57 GMT