Skip to content

Commit

Permalink
Merge pull request #482 from dice-group/neural_reasoner_retrieve_subc…
Browse files Browse the repository at this point in the history
…oncepts_recursively

subconcepts is now recursive
  • Loading branch information
Demirrr authored Nov 8, 2024
2 parents 0f2cea7 + 5e6a8c5 commit 9c75a07
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ontolearn/owl_neural_reasoner.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,20 @@ def classes_in_signature(self) -> List[OWLClass]:
return [OWLClass(top_entity) for top_entity, score in self.predict(h=None,
r=self.str_iri_type,
t=self.str_iri_owl_class)]
def subconcepts(self, named_concept: OWLClass) -> List[OWLClass]:
def direct_subconcepts(self, named_concept: OWLClass) -> List[OWLClass]:
return [OWLClass(top_entity) for top_entity, score in self.predict(h=None,
r=self.str_iri_subclassof,
t=named_concept.str)]

def subconcepts(self, named_concept: OWLClass) -> List[OWLClass]:
all_subconcepts = []
for subconcept in self.direct_subconcepts(named_concept):
# if subconcept is not valid class we can get invaild subconcepts for it resulting in infinite loop
if subconcept not in self.classes_in_signature():
return []
all_subconcepts.append(subconcept)
all_subconcepts.extend(self.subconcepts(subconcept))
return all_subconcepts

def most_general_classes(self) -> List[OWLClass]: # pragma: no cover
"""At least it has single subclass and there is no superclass"""
Expand Down

0 comments on commit 9c75a07

Please sign in to comment.