Getting all rdf: Class ancestors

Imagine the following taxonomy (acyclic and directed graph):

<my:Eukaryota> <rdfs:subClassOf> <my:Organism>. <my:Mammal> <rdfs:subClassOf> <my:Eukaryota>. <my:Primate> <rdfs:subClassOf> <my:Mammal>. <my:HomoSapiens> <rdfs:subClassOf> <my:Primate>. <my:Bacteria> <rdfs:subClassOf> <my:Organism>. <my:Escherichia> <rdfs:subClassOf> <my:Bacteria>. 

1) Is it possible to use the Jena OWL API to check whether a given resource (for example, HomoSapiens) is a subclass of "Mammal" without recursively retrieving all the parent nodes?

2) The same question with SPARQL .

thanks

+4
source share
4 answers

If you are already using Jena, you can use the Pellet query engine SPARQL-DL , which should allow you to query individual users in an ontological way.

Alternatively, you can use Jena InfModel instead of the Model interface, attach an argument (and ontology) to it, and then run the RobV query. You can use Pellet Browser if you want. You do not need to use OntModel if you just want to make reasoning.

+4
source

1) Did not use Jena a lot, but the OntTools class seems to contain functions for the lowest common ancestor. If the least common ancestor of HomoSapiens and a mammal is a mammal, then HomoSapiens is a mammal. Under the hood, it uses the recursive search subClassOf.

2) In general, no, SPARQL does not support arbitrary tree traversal. But if you know the maximum depth of the subClassOf tree, you can build a query like

 ASK { OPTIONAL { :HomoSapiens rdfs:subClassOf :Mammal } OPTIONAL { :HomoSapiens rdfs:subClassOf ?c . ?c rdfs:subClassOf :Mammal } OPTIONAL { :HomoSapiens rdfs:subClassOf ?c1 . ?c1 rdfs:subClassOf ?c2 . ?c2 rdfs:subClassOf :Mammal } # ... add } 
+3
source

laalto is right, almost any Semantic Web library is going to do this through a recursive search for subClassOf. The only way you could get around this is to have an inference / reasoning mechanism that will add extra triples to the graph when the original graph is analyzed.

So, for example, it will automatically add the following:

 <my:Eukaryota> <rdf:type> <my:Organism>. <my:Mammal> <rdf:type> <my:Organism>. <my:Mammal> <rdf:type> <my:Eukaryota>. <my:Primate> <rdfs:type> <my:Organism>. <my:Primate> <rdfs:type> <my:Eukaryota>. <my:Primate> <rdfs:type> <my:Mammal>. # etc... 

How do you do it in jena. I'm not sure anyone who knows that Jena will have to answer this question.

As in the case of SPARQL laalto, you are absolutely right, in some cases, although you can make a simple query, for example, the following: if the three-element store and the associated SPARQL endpoint have some output options

 PREFIX my: <http://yournamespace.com> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ASK { my:HomoSapiens rdf:type my:Mammal } 
+2
source

SPARQL 1.1 has an arbitrary intersection of the depth graph. What can be used for this. See Related Question on BioStar

ASK {: HomoSapiens rdfs: subClassOf +: Mammals}

+1
source

All Articles