Re: Accessing inferences and asserstions rather than just assertions
Posted by Jiba on
URL: http://owlready.306.s1.nabble.com/Accessing-inferences-and-asserstions-rather-than-just-assertions-tp144p159.html
Hi,
I've investigated this.
The problem is that:
1) RDFlib works at the RDF level, not the OWL level. However, inverseProperties are defined in OWL, not in RDF. Thus, RDFlib ignores inverseProperties when performing SPARQL queries.
2) HermiT is classifier: it classifies classes, but not relations. For example, if "inv" is the inverse of "rel" and we assert that "A rel B", HermiT will not deduce that "B inv A". This is not needed for Owlready, because Owlready works at the OWL level and it will deal with inverseProperties as expected. So, asserting "A rel B" is enough in Owlready, and you do not need to use the reasoning for inverseProperty values.
In Protege, inverseProperty values are shown after classification, but I'm not sure they come from HermiT. Deducing inverseProperty values is rather trivial and do not require a reasoner. When exporting inferred axioms as ontology in Protege, you can export inverseProperty values, but by default this option is not checked, because inverseProperty values are usually not asserted in ontologies.
For your problem, maybe the easier solution is to use Owlready's search() function (which takes inverseProperties into account). It is also faster than RDFlib's SPARQL engine.
For example :
from owlready2 import *
world = World()
onto = world.get_ontology("file:///tmp/t2.owl").load()
# Search all instances that entered something
entered_sometings = world.search(entered = "*")
# Search all instances that contains something that entered something
contain_entered_sometings = []
for i in entered_sometings:
contain_entered_sometings.extend(world.search(contains = i))
print(contain_entered_sometings)
In future version of Owlready, I might improve the RDFlib graph support so as it takes inverseProperties into account.
Best regards,
Jiba