You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Johan Kumps <jo...@telenet.be> on 2021/01/19 22:23:25 UTC

What is the best way to retrieve instances of equivalent classes / properties

I have these triples in my DB:

<http://www.co-ode.org/ontologies/ont.owl#myCar>
        a       owl:NamedIndividual , first:Car .
<http://www.co-ode.org/ontologies/ont.owl#Car>  a    owl:Class .
<http://www.co-ode.org/ontologies/ont.owl#myAutomobile>
        a       owl:NamedIndividual , first:Automobile .
<http://www.co-ode.org/ontologies/ont.owl#Automobile>  a          owl:Class ;
        owl:equivalentClass  first:Car .

I wat to retrieve all Car and Automobile individuals. Now I use this query:

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sosa: <http://www.w3.org/ns/sosa/>
PREFIX saref: <https://saref.etsi.org/core/>
PREFIX so: <http://purl.org/ontology/symbolic-music/>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix cars: <http://www.w3.org/2002/03owlt/equivalentClass/premises001#>
SELECT DISTINCT ?s ?type Where {
  {
    SELECT ?s ?type WHERE
        {
          ?type owl:equivalentClass cars:Car .
        ?s rdf:type ?type
        }
  } UNION {
    SELECT ?s ?type WHERE
        {
        ?s rdf:type cars:Car .
        ?s rdf:type ?type
        }
  }
  FILTER(?type != <http://www.w3.org/2002/07/owl#NamedIndividual>)
}

The result is :

<http://www.co-ode.org/ontologies/ont.owl#myAutomobile> cars:Automobile
<http://www.co-ode.org/ontologies/ont.owl#myCar> cars:Car

which is ok. Apparently there is a different result if I use this query :

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sosa: <http://www.w3.org/ns/sosa/>
PREFIX saref: <https://saref.etsi.org/core/>
PREFIX so: <http://purl.org/ontology/symbolic-music/>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix cars: <http://www.w3.org/2002/03owlt/equivalentClass/premises001#>
SELECT DISTINCT ?s ?type Where {
  {
    SELECT ?s ?type WHERE
        {
          ?type owl:equivalentClass cars:Automobile .
        ?s rdf:type ?type
        }
  } UNION {
    SELECT ?s ?type WHERE
        {
        ?s rdf:type cars:Automobile .
        ?s rdf:type ?type
        }
  }
  FILTER(?type != <http://www.w3.org/2002/07/owl#NamedIndividual>)
}

In this case only
http://www.co-ode.org/ontologies/ont.owl#myAutomobile cars:Automobile
is returned. I'm using the OWLFBRuleReasoner together with the
GenericRuleReasoner as follows on top of a TDB2 dataset:

:modelInf rdf:type ja:InfModel;
    ja:baseModel :modelInfOwl ;
    ja:reasoner [
        ja:reasonerURL <http://jena.hpl.hp.com/2003/GenericRuleReasoner>
    ] ;
.

:modelInfOwl rdf:type ja:InfModel;
    ja:baseModel :tdbGraph ;
    ja:reasoner [
        ja:reasonerURL <http://jena.hpl.hp.com/2003/OWLFBRuleReasoner>
    ] ;
.

:tdbGraph rdf:type tdb2:GraphTDB ;
  tdb2:dataset siot:dataset .

What could wrong or done better at my end?

Thanks in advance, Johan,

Re: What is the best way to retrieve instances of equivalent classes / properties

Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
The "problem" with the second query that RDF data is directed. You have
a triple (ignore the namespace prefixes please, your example and query
do use different ones, I omit all for brevity)

:Automobile  owl:equivalentClass  :Car .

so, subject is :Automobile and the object :Car.

Indeed this data matches the triple pattern 

?type owl:equivalentClass :Car .

But it does not match  

?type owl:equivalentClass :Automobile .

as :Automobile isn **not** used as the object in the RDF triple. 

the common pattern nowadays is to use property paths like

(owl:equivalentClass|^owl:equivalentClass)

and indeed this is for away from being complete. Full OWL DL reasoning can't be rewritten anyways, but there are some property paths that are supposed to be as complete as possible like

|(rdfs:subClassOf|(owl:equivalentClass|^owl:equivalentClass))* but
again, not really covers all. Imagine having intersections as class
expressions like SmallCar SubClassOf (Car And SmallObject). OWL
Intersections are modelled by RDF lists, thus, you'd also have to
resolve this, e.g. by |
||(rdfs:subClassOf|(owl:intersectionOf/rdf:rest*/rdf:first))* Anyways,
for your simple dataset, you can stick with | |(owl:equivalentClass|^owl:equivalentClass)

for transitive closure do 

(owl:equivalentClass|^owl:equivalentClass)*

And yes, things getting more expensive with every component.

Otherwise, using a reasoner and materializing the facts once is another way to go and makes the query less expensive (and slow)  
||

 
On 19.01.21 23:23, Johan Kumps wrote:
> I have these triples in my DB:
>
> <http://www.co-ode.org/ontologies/ont.owl#myCar>
>         a       owl:NamedIndividual , first:Car .
> <http://www.co-ode.org/ontologies/ont.owl#Car>  a    owl:Class .
> <http://www.co-ode.org/ontologies/ont.owl#myAutomobile>
>         a       owl:NamedIndividual , first:Automobile .
> <http://www.co-ode.org/ontologies/ont.owl#Automobile>  a          owl:Class ;
>         owl:equivalentClass  first:Car .
>
> I wat to retrieve all Car and Automobile individuals. Now I use this query:
>
> PREFIX owl: <http://www.w3.org/2002/07/owl#>
> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
> PREFIX sosa: <http://www.w3.org/ns/sosa/>
> PREFIX saref: <https://saref.etsi.org/core/>
> PREFIX so: <http://purl.org/ontology/symbolic-music/>
> prefix foaf: <http://xmlns.com/foaf/0.1/>
> prefix cars: <http://www.w3.org/2002/03owlt/equivalentClass/premises001#>
> SELECT DISTINCT ?s ?type Where {
>   {
>     SELECT ?s ?type WHERE
>         {
>           ?type owl:equivalentClass cars:Car .
>         ?s rdf:type ?type
>         }
>   } UNION {
>     SELECT ?s ?type WHERE
>         {
>         ?s rdf:type cars:Car .
>         ?s rdf:type ?type
>         }
>   }
>   FILTER(?type != <http://www.w3.org/2002/07/owl#NamedIndividual>)
> }
>
> The result is :
>
> <http://www.co-ode.org/ontologies/ont.owl#myAutomobile> cars:Automobile
> <http://www.co-ode.org/ontologies/ont.owl#myCar> cars:Car
>
> which is ok. Apparently there is a different result if I use this query :
>
> PREFIX owl: <http://www.w3.org/2002/07/owl#>
> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
> PREFIX sosa: <http://www.w3.org/ns/sosa/>
> PREFIX saref: <https://saref.etsi.org/core/>
> PREFIX so: <http://purl.org/ontology/symbolic-music/>
> prefix foaf: <http://xmlns.com/foaf/0.1/>
> prefix cars: <http://www.w3.org/2002/03owlt/equivalentClass/premises001#>
> SELECT DISTINCT ?s ?type Where {
>   {
>     SELECT ?s ?type WHERE
>         {
>           ?type owl:equivalentClass cars:Automobile .
>         ?s rdf:type ?type
>         }
>   } UNION {
>     SELECT ?s ?type WHERE
>         {
>         ?s rdf:type cars:Automobile .
>         ?s rdf:type ?type
>         }
>   }
>   FILTER(?type != <http://www.w3.org/2002/07/owl#NamedIndividual>)
> }
>
> In this case only
> http://www.co-ode.org/ontologies/ont.owl#myAutomobile cars:Automobile
> is returned. I'm using the OWLFBRuleReasoner together with the
> GenericRuleReasoner as follows on top of a TDB2 dataset:
>
> :modelInf rdf:type ja:InfModel;
>     ja:baseModel :modelInfOwl ;
>     ja:reasoner [
>         ja:reasonerURL <http://jena.hpl.hp.com/2003/GenericRuleReasoner>
>     ] ;
> .
>
> :modelInfOwl rdf:type ja:InfModel;
>     ja:baseModel :tdbGraph ;
>     ja:reasoner [
>         ja:reasonerURL <http://jena.hpl.hp.com/2003/OWLFBRuleReasoner>
>     ] ;
> .
>
> :tdbGraph rdf:type tdb2:GraphTDB ;
>   tdb2:dataset siot:dataset .
>
> What could wrong or done better at my end?
>
> Thanks in advance, Johan,
>