- From: Paul Gearon <gearon@ieee.org>
- Date: Thu, 5 Nov 2009 15:00:59 -0500
- To: Etienne Morency <etienne.morency@gmail.com>
- Cc: OWL Dev <public-owl-dev@w3.org>
Hi Etienne, This is an RDF and SPARQL issue, and not really appropriate for an OWL list. This is especially so, given that most of the OWL community are against the use of Containers (especially the DL folks). I recommend mailing lists such as semantic-web@w3.org, or possibly www-rdf-interest@w3.org. But since I'm here.... On Tue, Nov 3, 2009 at 4:48 PM, Etienne Morency <etienne.morency@gmail.com> wrote: > Hi everyone, > > We are using sequences in our project and we are having difficulties finding > a way to query our ontology to get all items of a sequence using SPARQL. I mentioned that containers (including sequences) are not encouraged by the OWL community. While I expect to see them used in general RDF, I'm a little surprised to see them in a system described by OWL. I'm sure there are a few people here willing to discuss this design decision with you, but I'll just press ahead with your question. After all, querying members of collections is just as awkward with SPARQL 1.0. :-) > The sequence in our ontology looks like this : > > <rdf:Seq rdf:about="http://www.url.com/someonto.owl#1317"/> > > <rdf:Seq rdf:about="http://www.url.com/someonto.owl#1317"/> > <rdf:_1 rdf:resource="http://www.url.com/someonto.owl#314"/> > </rdf:Description> > > <rdf:Seq rdf:about="http://www.url.com/someonto.owl#1317"/> > <rdf:_2 rdf:resource="http://www.url.com/someonto.owl#194"/> > </rdf:Description> > > <rdf:Seq rdf:about="http://www.url.com/someonto.owl#1317"/> > <rdf:_3 rdf:resource="http://www.url.com/someonto.owl#GENERIC_113"/> > </rdf:Description> > > We are able to find the sequence "http://www.url.com/someonto.owl#1317" with > the following query : > SELECT ?sequence WHERE { ?sequence <" + RDF.TYPE + "> <" + RDF.SEQ + "> } > > But is there a way to have a query that will return the items _1, _2 and _3 > directly ? First off, since you have a sequence, you'd often want to know what the first thing is, the second thing is, etc, and you can select these out just by referring to the predicates rdf:_1, rdf:_2, and so on. But it looks like you want to get everything, so directly mentioning the predicates won't help. If you have RDFS entailments available, you can ask for the rdfs:member property, since all rdf:_n are subproperties of this: PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?sequence ?element WHERE { ?sequence rdf:type rdf:Seq . ?sequence rdfs:member ?element } However, this loses your ordering. You can try to get the associated predicate (add {?sequence ?pred ?element} and remove the rdfs:member elements via OPTIONAL/!BOUND), but the SPARQL gets messy and we haven't even established if you have entailment available. 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. Regards, Paul Gearon
Received on Thursday, 5 November 2009 20:01:39 UTC