Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subconcepts is now recursive #482

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading