I am working with the FoodOn ontology and need to figure out if a certain class is somehow related to another class. Typical use case: Can a vegan person eat honey? No, because honey is a subsub class of "invertebrate animal food product"!
I am using the python owlready2 library which allows me to run SPARQL queries and query subclass relations like this:
SELECT ?class
WHERE
{
# honey
<http://purl.obolibrary.org/obo/UBERON_0036016> rdfs:subClassOf* ?class .
# animal food product
?class rdfs:subClassOf* <http://purl.obolibrary.org/obo/FOODON_00001176>
}
This code gives me the full subclass path between honey and animal food product - great.
My problem is, that the relationship is not always that of a subclass. Let's look at "vegetarian food product" using the Protege editor:
We can see that "vegetarian food product" is a subclass of "food product by organism" but at the same time it is also equivalent to 'food product' and (not ('derives from' some ('invertebrate animal' or 'vertebrate animal'))).
If I look at all triples using SPARQL I get the subclass relationship but the equivalentClass is just a bnode:
(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#subClassOf'),
rdflib.term.URIRef('http://purl.obolibrary.org/obo/FOODON_00002381')),
(rdflib.term.URIRef('http://www.w3.org/2002/07/owl#equivalentClass'),
rdflib.term.BNode('5846'))
[stripped some output]
- Why does SPARQL not return all relationships?
- How can I query for all classes that are either a subclass of 'vegetarian food product' or related to it by some other object property?
- Also, how can I query for the 'AND' and 'OR' component in the example above?
I do accept non-python solutions as long as it can be automated. Protege has a DL Query tab but I think that I cannot export the results using the UI...
Thank you!