diff --git a/owlapy/owl_ontology.py b/owlapy/owl_ontology.py index 5f400401..fc4cd5eb 100644 --- a/owlapy/owl_ontology.py +++ b/owlapy/owl_ontology.py @@ -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] @@ -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()) @@ -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. @@ -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]: diff --git a/tests/test_sync_ontology_read_write.py b/tests/test_sync_ontology_read_write.py new file mode 100644 index 00000000..43c1beb0 --- /dev/null +++ b/tests/test_sync_ontology_read_write.py @@ -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()]) \ No newline at end of file