Re: Is this possible in SPARQL?

Johann Petrak wrote:
> I have a triple store that contains triples representing
> an OWL-Lite ontology.
> All the facts that can be derived from that ontology are
> explicitly asserted.
> 
> The question is now: is it possible to make a SPARQL query
> that will retrieve a list of top classes?
> A top class would be defined as something that has
> rdf:type owl:Class and is not rdfs:subClassOf a
> *different* class other than owl:Thing or rdfs:Resource.
> A different class is a class that is not directly or
> indirectly related via a owl:equivalentClass relationship.
> Every class is a subclass of owl:Thing, of itself, and
> of all classes that are related via owl:equivalentClass.
> 
> The problem are the equivalent classes. The following
> query will find all the top classes, but incorrectly
> remove any class that is an equivalent class of some
> other class:
> 
> SELECT DISTINCT ?cl WHERE
>   { ?cl a owl:Class }
>   OPTIONAL {
>      ?cl rdfs:subClassOf ?sc .
>      FILTER (?cl != ?sc && ?sc != owl:Thing && ?sc != rdfs:Resource)
>   }
>   FILTER (!bound(?sc))
> 
> Is there any way to accomplish this in a single SPARQL query?
> And if not, what would the approach for doing this with least
> performance effort in multiple queries?

Hi Johann,

In current SPARQL, triple patterns can only query for fixed length paths 
through the graph. There's no way to ask for arbitrary length paths of 
owl:equivalentClass statements. If all owl:equivalentClass statements 
are pairwise explicitly asserted in your store, then you should be able 
to do:

SELECT DISTINCT ?cl WHERE
{
   { ?cl a owl:Class }
   OPTIONAL {
      { ?cl rdfs:subClassOf ?sc . }
   UNION
      { ?cl rdfs:subClassOf [ owl:equivalentClass ?sc ] }
      FILTER (?cl != ?sc && ?sc != owl:Thing && ?sc != rdfs:Resource)
   }
   FILTER (!bound(?sc))
}

Lee

> Since SERQL supports nested selects and the minus, any etc.
> operators, this can be done in one SERQL query.
> 
> 
> 

Received on Monday, 31 August 2009 10:06:08 UTC