From 35e04fed91d59a48de007ca5ff120a8bacd3b5a8 Mon Sep 17 00:00:00 2001 From: Alkid Date: Wed, 11 Sep 2024 11:41:04 +0200 Subject: [PATCH 1/3] updated to owlapy 1.3.0 --- examples/example_reasoner.py | 12 ++++++------ ontolearn/base_concept_learner.py | 14 +++++++------- ontolearn/learning_problem_generator.py | 6 +++--- ontolearn/utils/static_funcs.py | 4 ++-- setup.py | 2 +- tests/test_knowledge_base.py | 16 ++++++++-------- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/examples/example_reasoner.py b/examples/example_reasoner.py index 677167f9..5b953a58 100644 --- a/examples/example_reasoner.py +++ b/examples/example_reasoner.py @@ -118,14 +118,14 @@ onto = kb.ontology manager = onto.get_owl_ontology_manager() -manager.add_axiom(onto, OWLEquivalentObjectPropertiesAxiom([r6, r5])) -manager.add_axiom(onto, OWLEquivalentObjectPropertiesAxiom([r5, r6])) -manager.add_axiom(onto, OWLObjectPropertyDomainAxiom(r1, ST)) +onto.add_axiom(OWLEquivalentObjectPropertiesAxiom([r6, r5])) +onto.add_axiom(OWLEquivalentObjectPropertiesAxiom([r5, r6])) +onto.add_axiom(OWLObjectPropertyDomainAxiom(r1, ST)) -manager.add_axiom(onto, OWLSubClassOfAxiom(R, r5Q)) -manager.add_axiom(onto, OWLSubClassOfAxiom(ST, U)) +onto.add_axiom(OWLSubClassOfAxiom(R, r5Q)) +onto.add_axiom(OWLSubClassOfAxiom(ST, U)) -# manager.save_ontology(onto, IRI.create('file:/' + 'test' + '.owl')) +# onto.save(IRI.create('file:/' + 'test' + '.owl')) base_reasoner = OntologyReasoner(onto) # reasoner = FastInstanceCheckerReasoner( diff --git a/ontolearn/base_concept_learner.py b/ontolearn/base_concept_learner.py index b10421ed..34a86ad6 100644 --- a/ontolearn/base_concept_learner.py +++ b/ontolearn/base_concept_learner.py @@ -303,7 +303,7 @@ def predict(self, individuals: List[OWLNamedIndividual], ontology: OWLOntology = cast(Ontology, self.kb.ontology) manager: OWLOntologyManager = ontology.get_owl_ontology_manager() for axiom in axioms: - manager.add_axiom(ontology, axiom) + ontology.add_axiom(axiom) if reasoner is None: reasoner = FastInstanceCheckerReasoner(ontology, base_reasoner=OntologyReasoner(ontology)) @@ -322,9 +322,9 @@ def predict(self, individuals: List[OWLNamedIndividual], # Remove the axioms from the ontology if axioms is not None: for axiom in axioms: - manager.remove_axiom(ontology, axiom) + ontology.remove_axiom(axiom) for ind in individuals: - manager.remove_axiom(ontology, OWLDeclarationAxiom(ind)) + ontology.remove_axiom(OWLDeclarationAxiom(ind)) return predictions @@ -362,7 +362,7 @@ def save_best_hypothesis(self, n: int = 10, path: str = 'Predictions', rdf_forma for ith, h in enumerate(self.best_hypotheses(n=n)): cls_a: OWLClass = OWLClass(IRI.create(NS, "Pred_" + str(ith))) equivalent_classes_axiom = OWLEquivalentClassesAxiom([cls_a, h]) - manager.add_axiom(ontology, equivalent_classes_axiom) + ontology.add_axiom(equivalent_classes_axiom) # @TODO:CD: We should find a way to include information (F1score etc) outside of OWL class expression instances """ try: @@ -373,14 +373,14 @@ def save_best_hypothesis(self, n: int = 10, path: str = 'Predictions', rdf_forma if isinstance(self.quality_func, Accuracy): accuracy = OWLAnnotationAssertionAxiom(cls_a.iri, OWLAnnotation( OWLAnnotationProperty(IRI.create(SNS, "accuracy")), OWLLiteral(quality))) - manager.add_axiom(ontology, accuracy) + ontology.add_axiom(accuracy) elif isinstance(self.quality_func, F1): f1_score = OWLAnnotationAssertionAxiom(cls_a.iri, OWLAnnotation( OWLAnnotationProperty(IRI.create(SNS, "f1_score")), OWLLiteral(quality))) - manager.add_axiom(ontology, f1_score) + ontology.add_axiom(f1_score) """ - manager.save_ontology(ontology, IRI.create('file:/' + path + '.owl')) + ontology.save(IRI.create('file:/' + path + '.owl')) def load_hypotheses(self, path: str) -> Iterable[OWLClassExpression]: """ diff --git a/ontolearn/learning_problem_generator.py b/ontolearn/learning_problem_generator.py index ef0530e1..77bd0ae7 100644 --- a/ontolearn/learning_problem_generator.py +++ b/ontolearn/learning_problem_generator.py @@ -104,7 +104,7 @@ def export_concepts(self, concepts: List[Node], path: str): for ith, h in enumerate(concepts): cls_a: OWLClass = OWLClass(IRI.create(NS, "Pred_" + str(ith))) equivalent_classes_axiom = OWLEquivalentClassesAxiom([cls_a, h.concept]) - manager.add_axiom(ontology, equivalent_classes_axiom) + ontology.add_axiom(equivalent_classes_axiom) count = None try: @@ -118,9 +118,9 @@ def export_concepts(self, concepts: List[Node], path: str): if count is not None: num_inds = OWLAnnotationAssertionAxiom(cls_a.iri, OWLAnnotation( OWLAnnotationProperty(IRI.create(SNS, "covered_inds")), OWLLiteral(count))) - manager.add_axiom(ontology, num_inds) + ontology.add_axiom(num_inds) - manager.save_ontology(ontology, IRI.create('file:/' + path + '.owl')) + ontology.save(IRI.create('file:/' + path + '.owl')) def concept_individuals_to_string_balanced_examples(self, concept: OWLClassExpression) -> Dict[str, Set]: diff --git a/ontolearn/utils/static_funcs.py b/ontolearn/utils/static_funcs.py index 4b08f978..beca8902 100644 --- a/ontolearn/utils/static_funcs.py +++ b/ontolearn/utils/static_funcs.py @@ -311,7 +311,7 @@ def save_owl_class_expressions(expressions: Union[OWLClassExpression, List[OWLCl cls_a = OWLClass(IRI.create(NS, str(th))) equivalent_classes_axiom = OWLEquivalentClassesAxiom([cls_a, i]) try: - manager.add_axiom(ontology, equivalent_classes_axiom) + ontology.add_axiom(equivalent_classes_axiom) except AttributeError: print(traceback.format_exc()) print("Exception at creating OWLEquivalentClassesAxiom") @@ -320,7 +320,7 @@ def save_owl_class_expressions(expressions: Union[OWLClassExpression, List[OWLCl print(i) print(expressions) exit(1) - manager.save_ontology(ontology, IRI.create('file:/' + path + '.owl')) + ontology.save(IRI.create('file:/' + path + '.owl')) def verbalize(predictions_file_path: str): # pragma: no cover diff --git a/setup.py b/setup.py index 5c0153f3..81f0c74c 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ "tqdm>=4.64.0", "transformers>=4.38.1", "pytest>=7.2.2", - "owlapy==1.2.1", + "owlapy==1.3.0", "dicee==0.1.4", "ontosample>=0.2.2", "sphinx>=7.2.6", diff --git a/tests/test_knowledge_base.py b/tests/test_knowledge_base.py index 0a457196..be140478 100644 --- a/tests/test_knowledge_base.py +++ b/tests/test_knowledge_base.py @@ -143,13 +143,13 @@ def test_property_retrieval(self): # indirect object property values of an individual super_in_bond = OWLObjectProperty(IRI.create(self.namespace, 'super_inBond')) - self.mgr.add_axiom(self.onto, OWLSubObjectPropertyOfAxiom(self.in_bond, super_in_bond)) + self.onto.add_axiom(OWLSubObjectPropertyOfAxiom(self.in_bond, super_in_bond)) inds = frozenset(self.kb.get_object_property_values(self.bond5225, super_in_bond, direct=False)) true_inds = {self.d91_32, self.d91_17} self.assertEqual(true_inds, inds) inds = frozenset(self.kb.get_object_property_values(self.bond5225, super_in_bond, direct=True)) self.assertEqual(frozenset(), inds) - self.mgr.remove_axiom(self.onto, OWLSubObjectPropertyOfAxiom(self.in_bond, super_in_bond)) + self.onto.remove_axiom(OWLSubObjectPropertyOfAxiom(self.in_bond, super_in_bond)) # data property values of an individual values = frozenset(self.kb.get_data_property_values(self.d91_32, self.charge, direct=True)) @@ -158,13 +158,13 @@ def test_property_retrieval(self): # indirect data property values of an individual super_charge = OWLDataProperty(IRI.create(self.namespace, 'super_charge')) - self.mgr.add_axiom(self.onto, OWLSubDataPropertyOfAxiom(self.charge, super_charge)) + self.onto.add_axiom(OWLSubDataPropertyOfAxiom(self.charge, super_charge)) values = frozenset(self.kb.get_data_property_values(self.d91_32, super_charge, direct=False)) true_values = {OWLLiteral(0.146)} self.assertEqual(true_values, values) values = frozenset(self.kb.get_data_property_values(self.d91_32, super_charge, direct=True)) self.assertEqual(frozenset(), values) - self.mgr.remove_axiom(self.onto, OWLSubDataPropertyOfAxiom(self.charge, super_charge)) + self.onto.remove_axiom(OWLSubDataPropertyOfAxiom(self.charge, super_charge)) # object properties of an individual properties = frozenset(self.kb.get_object_properties_for_ind(self.bond5225, direct=True)) @@ -172,14 +172,14 @@ def test_property_retrieval(self): self.assertEqual(true_properties, properties) # indirect object properties of an individual - self.mgr.add_axiom(self.onto, OWLSubObjectPropertyOfAxiom(self.in_bond, self.has_bond)) + self.onto.add_axiom(OWLSubObjectPropertyOfAxiom(self.in_bond, self.has_bond)) properties = frozenset(self.kb.get_object_properties_for_ind(self.bond5225, direct=False)) true_properties = {self.in_bond, self.has_bond} self.assertEqual(true_properties, properties) properties = frozenset(self.kb.get_object_properties_for_ind(self.bond5225, direct=True)) true_properties = {self.in_bond} self.assertEqual(true_properties, properties) - self.mgr.remove_axiom(self.onto, OWLSubObjectPropertyOfAxiom(self.in_bond, self.has_bond)) + self.onto.remove_axiom(OWLSubObjectPropertyOfAxiom(self.in_bond, self.has_bond)) # data properties of an individual properties = frozenset(self.kb.get_data_properties_for_ind(self.d91_32, direct=True)) @@ -187,14 +187,14 @@ def test_property_retrieval(self): self.assertEqual(true_properties, properties) # indirect data properties of an individual - self.mgr.add_axiom(self.onto, OWLSubDataPropertyOfAxiom(self.charge, self.act)) + self.onto.add_axiom(OWLSubDataPropertyOfAxiom(self.charge, self.act)) properties = frozenset(self.kb.get_data_properties_for_ind(self.d91_32, direct=False)) true_properties = {self.charge, self.act} self.assertEqual(true_properties, properties) properties = frozenset(self.kb.get_data_properties_for_ind(self.d91_32, direct=True)) true_properties = {self.charge} self.assertEqual(true_properties, properties) - self.mgr.remove_axiom(self.onto, OWLSubDataPropertyOfAxiom(self.charge, self.act)) + self.onto.remove_axiom(OWLSubDataPropertyOfAxiom(self.charge, self.act)) def test_ignore(self): concepts_to_ignore = {self.bond1, self.compound} From 69ebf8aac42f2a42bbc54daedc98f1f171e8ccb9 Mon Sep 17 00:00:00 2001 From: Alkid Date: Sat, 14 Sep 2024 18:31:54 +0200 Subject: [PATCH 2/3] increased version to 0.7.4 --- README.md | 4 ++-- docs/usage/01_introduction.md | 2 +- ontolearn/__init__.py | 2 +- setup.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 41b89199..829f3c68 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Coverage](https://img.shields.io/badge/coverage-95%25-green)](https://ontolearn-docs-dice-group.netlify.app/usage/09_further_resources#code-coverage) -[![Pypi](https://img.shields.io/badge/pypi-0.7.3-blue)](https://pypi.org/project/ontolearn/0.7.3/) -[![Docs](https://img.shields.io/badge/documentation-0.7.3-yellow)](https://ontolearn-docs-dice-group.netlify.app/usage/01_introduction) +[![Pypi](https://img.shields.io/badge/pypi-0.7.4-blue)](https://pypi.org/project/ontolearn/0.7.4/) +[![Docs](https://img.shields.io/badge/documentation-0.7.4-yellow)](https://ontolearn-docs-dice-group.netlify.app/usage/01_introduction) [![Python](https://img.shields.io/badge/python-3.10.13+-4584b6)](https://www.python.org/downloads/release/python-31013/)   diff --git a/docs/usage/01_introduction.md b/docs/usage/01_introduction.md index bdb41472..636d0fbc 100644 --- a/docs/usage/01_introduction.md +++ b/docs/usage/01_introduction.md @@ -1,6 +1,6 @@ # About Ontolearn -**Version:** ontolearn 0.7.3 +**Version:** ontolearn 0.7.4 **GitHub repository:** [https://github.com/dice-group/Ontolearn](https://github.com/dice-group/Ontolearn) diff --git a/ontolearn/__init__.py b/ontolearn/__init__.py index e5863def..c69e25b1 100644 --- a/ontolearn/__init__.py +++ b/ontolearn/__init__.py @@ -22,4 +22,4 @@ # SOFTWARE. # ----------------------------------------------------------------------------- -__version__ = '0.7.3' +__version__ = '0.7.4' diff --git a/setup.py b/setup.py index 81f0c74c..ecd50b67 100644 --- a/setup.py +++ b/setup.py @@ -94,7 +94,7 @@ def deps_list(*pkgs): setup( name="ontolearn", description="Ontolearn is an open-source software library for structured machine learning in Python. Ontolearn includes modules for processing knowledge bases, inductive logic programming and ontology engineering.", - version="0.7.3", + version="0.7.4", packages=find_packages(), install_requires=extras["min"], extras_require=extras, From 3ca5d6fc3e7fdd99dac84ee869a1a09a97a2bdec Mon Sep 17 00:00:00 2001 From: Alkid Date: Sat, 14 Sep 2024 18:38:39 +0200 Subject: [PATCH 3/3] added the missing "s" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 829f3c68..953f97f1 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ![Ontolearn](docs/_static/images/Ontolearn_logo.png) -# Ontolearn: Learning OWL Class Expression +# Ontolearn: Learning OWL Class Expressions *Ontolearn* is an open-source software library for learning owl class expressions at large scale.