Skip to content

Commit

Permalink
Test added todos for Ontology added
Browse files Browse the repository at this point in the history
  • Loading branch information
Demirrr committed Nov 25, 2024
1 parent 460de76 commit d0c233f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
17 changes: 10 additions & 7 deletions owlapy/owl_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,17 +826,18 @@ def properties_in_signature(self) -> Iterable[OWLProperty]:
def individuals_in_signature(self) -> Iterable[OWLNamedIndividual]:
for i in self._onto.individuals():
yield OWLNamedIndividual(IRI.create(i.iri))

def tbox_axioms(self)->Iterable:
def get_abox_axioms(self)->Iterable:
# @TODO: CD: Return all information between owl classes, e.g. subclass or disjoint
raise NotImplementedError("will be implemented in future")
def get_tbox_axioms(self)->Iterable:
# @TODO: CD: Return all information between owl classes, e.g. subclass or disjoint
raise NotImplementedError("will be implemented in future")
def abox_axioms_between_individuals(self)->Iterable:
def get_abox_axioms_between_individuals(self)->Iterable:
# @TODO: CD: Return all information between owl_individuals, i.e., triples with object properties
raise NotImplementedError("will be implemented in future")
def abox_axioms_between_individuals_and_classes(self)->Iterable:
def get_abox_axioms_between_individuals_and_classes(self)->Iterable:
# @TODO: CD: Return all type information about individuals, i.e., individual type Class
raise NotImplementedError("will be implemented in future")

# @TODO:CD:Unsure it is working
def equivalent_classes_axioms(self, c: OWLClass) -> Iterable[OWLEquivalentClassesAxiom]:
c_x: owlready2.ThingClass = self._world[c.str]
Expand Down Expand Up @@ -1019,6 +1020,9 @@ def __repr__(self):
f'\t|Data Properties|={len(self.data_properties_in_signature())}'
f'\n{self.manager}\tPath:{self.path}\tNew:{self.new}')

def __len__(self):
return len([i for i in self.get_abox_axioms()] + [i for i in self.get_abox_axioms()])

def classes_in_signature(self) -> Iterable[OWLClass]:
return self.mapper.map_(self.owlapi_ontology.getClassesInSignature())

Expand Down Expand Up @@ -1056,6 +1060,7 @@ def _get_imports_enum(self, include_imports_closure: bool):
else:
imports = Imports.EXCLUDED
return imports

def get_signature(self, include_imports_closure: bool = True):
"""Gets the entities that are in the signature of this ontology.
Expand All @@ -1065,8 +1070,6 @@ def get_signature(self, include_imports_closure: bool = True):
Returns:
Entities in signature.
"""
# @TODO: CD: Is this class method redundant given that we have the individuals_in_signature ?
# AB re: This method does not return only individuals.
return self.mapper.map_(self.owlapi_ontology.getSignature(self._get_imports_enum(include_imports_closure)))

def get_abox_axioms(self, include_imports_closure: bool = True) -> Iterable[OWLAxiom]:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_sync_ontology_read_write.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest
from owlapy.owl_ontology_manager import SyncOntologyManager, OntologyManager



class TestSyncReasoner(unittest.TestCase):
def test_read_write(self):
# Create an empty ontology
o1 = SyncOntologyManager().create_ontology("file:/example_ontology.owl")
# () Add tbox axioms from another ontology
for axiom in SyncOntologyManager().load_ontology("KGs/Family/father.owl").get_tbox_axioms():
o1.add_axiom(axiom)
# () Add abox axioms from another ontology
for axiom in SyncOntologyManager().load_ontology("KGs/Family/father.owl").get_abox_axioms():
o1.add_axiom(axiom)
o1.save(path="demo.owl")
# Check the axiom numbers
abox = len([i for i in o1.get_abox_axioms()])
tbox = len([i for i in o1.get_tbox_axioms()])

o2 = SyncOntologyManager().load_ontology(path="demo.owl")
assert abox == len([i for i in o2.get_abox_axioms()])
assert tbox == len([i for i in o2.get_tbox_axioms()])

0 comments on commit d0c233f

Please sign in to comment.