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

updated to owlapy 1.3.0 #444

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[![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/)
 

![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.

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/01_introduction.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
12 changes: 6 additions & 6 deletions examples/example_reasoner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion ontolearn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
# SOFTWARE.
# -----------------------------------------------------------------------------

__version__ = '0.7.3'
__version__ = '0.7.4'
14 changes: 7 additions & 7 deletions ontolearn/base_concept_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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]:
"""
Expand Down
6 changes: 3 additions & 3 deletions ontolearn/learning_problem_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]:

Expand Down
4 changes: 2 additions & 2 deletions ontolearn/utils/static_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions tests/test_knowledge_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -158,43 +158,43 @@ 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))
true_properties = {self.in_bond}
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))
true_properties = {self.charge}
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}
Expand Down
Loading