You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Im trying to set up my project using ontolearn, specifically a KnowledgeBase using a SyncReasoner and I'm having trouble getting it to work. Here is a minimal example on the father.owl ontology and using ontolearn 0.8.1 and owlapy 1.3.3:
from ontolearn.knowledge_base import KnowledgeBase
from owlapy.owl_reasoner import SyncReasoner
from owlapy.owl_ontology_manager import SyncOntologyManager
from owlapy.class_expression import OWLClassExpression, OWLClass
from owlapy.iri import IRI
onto_file_path = "tests/data/father.owl"
ns = "http://example.com/father#"
manager = SyncOntologyManager()
onto = manager.load_ontology(onto_file_path)
reasoner = SyncReasoner(onto, reasoner="Openllet")
kb = KnowledgeBase(
ontology=onto,
reasoner=reasoner,
load_class_hierarchy=True,
)
#kb = KnowledgeBase(
# path=onto_file_path
#)
owl_expression = OWLClass(IRI(ns, "male"))
print(reasoner.instances(owl_expression))
for i in reasoner.instances(owl_expression):
print(i)
print(kb.individuals(owl_expression))
for i in kb.individuals(owl_expression):
print(i)
The stacktrace I get when I run this code is the following:
Traceback (most recent call last):
File "/home/cwrk/Work/semanticlog/tests/debugging.py", line 14, in <module>
kb = KnowledgeBase(
File "/home/cwrk/miniconda3/envs/semlog/lib/python3.10/site-packages/ontolearn/knowledge_base.py", line 188, in __init__
self.data_property_hierarchy) = init_hierarchy_instances(self.reasoner,
File "/home/cwrk/miniconda3/envs/semlog/lib/python3.10/site-packages/ontolearn/utils/static_funcs.py", line 162, in init_hierarchy_instances
class_hierarchy = ClassHierarchy(reasoner)
File "/home/cwrk/miniconda3/envs/semlog/lib/python3.10/site-packages/owlapy/owl_hierarchy.py", line 286, in __init__
super().__init__(OWLClass, arg)
File "/home/cwrk/miniconda3/envs/semlog/lib/python3.10/site-packages/owlapy/owl_hierarchy.py", line 51, in __init__
self._init(hier_down_gen)
File "/home/cwrk/miniconda3/envs/semlog/lib/python3.10/site-packages/owlapy/owl_hierarchy.py", line 124, in _init
_children_transitive(self._children_map_trans, ent=ent, seen_set=set())
File "/home/cwrk/miniconda3/envs/semlog/lib/python3.10/site-packages/owlapy/owl_hierarchy.py", line 397, in _children_transitive
_children_transitive(hier_trans, sub_ent, seen_set | {ent})
File "/home/cwrk/miniconda3/envs/semlog/lib/python3.10/site-packages/owlapy/owl_hierarchy.py", line 394, in _children_transitive
sub_classes_ent = frozenset(hier_trans[ent])
KeyError: OWLClass(IRI('http://www.w3.org/2002/07/owl#', 'Nothing'))
From the error I could gather that there is something wrong with how the class hierarchy of the KnowledgeBase gets initialized? If i set load_class_hierarchy=False it works, but then fails when I try to learn something. Alternatively, if I use something besides the SyncOntology/SyncReasoner it also works just fine. However, I need to be able to set the reasoner and thus need the SyncReasoner for my project.
Have I set something up wrong? Where are my mistakes? Are there some further resources, besides the documentation, examples and tests? So far I could not figure out how to make it work. Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
Hi @CronosC, your setup is fine and there is no mistake by your side.
Although SyncReasoner has been around for a while, it is considered experimental and we have not yet tested its integration with Ontolearn for any possible issue. However the error you are dealing is not directly related with the Ontolearn integration.
As you may have noticed we define hierarchies for classes and properties where the initialization includes setting transitive links between entities within a hierarchy. The error we have in hand here emerges from owlapi(the Java library we use in owlapy) where for some reason, bottom class/properties (owl:Nothing, owl:bottomObjectProperty, owl:bottomDataProperty) are considered a subclass/subproperty but not a class/property of the classes/properties in signature. However, we will look further into this issue and provide a solid solution on the next release.
Meanwhile if you need immediate solution you can make the following change in your local owlapy package:
# site-packages/owlapy/owl_hierarchy.py# line 116-119
for ent, sub_it in ent_to_sub_entities.items():
+ sub_it_without_bottom_entity = set(sub_it) - {OWLNothing, OWLBottomObjectProperty, OWLBottomDataProperty} - self._children_map_trans[ent] = set(sub_it)+ self._children_map_trans[ent] = sub_it_without_bottom_entity
self._parents_map_trans[ent] = set()
This is a temporary solution that I don't recommend anyone doing because its not tested, may potentially come with loss of information and the problem is still being investigated, but for now it will make your code work so you may continue with your experiments until we patch this problem.
Im trying to set up my project using ontolearn, specifically a KnowledgeBase using a SyncReasoner and I'm having trouble getting it to work. Here is a minimal example on the father.owl ontology and using ontolearn 0.8.1 and owlapy 1.3.3:
The stacktrace I get when I run this code is the following:
From the error I could gather that there is something wrong with how the class hierarchy of the KnowledgeBase gets initialized? If i set load_class_hierarchy=False it works, but then fails when I try to learn something. Alternatively, if I use something besides the SyncOntology/SyncReasoner it also works just fine. However, I need to be able to set the reasoner and thus need the SyncReasoner for my project.
Have I set something up wrong? Where are my mistakes? Are there some further resources, besides the documentation, examples and tests? So far I could not figure out how to make it work. Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered: