Skip to content

Commit

Permalink
Merge pull request #86 from dice-group/develop
Browse files Browse the repository at this point in the history
New release: owlapy 1.3.1
  • Loading branch information
alkidbaci authored Oct 17, 2024
2 parents 9a95b15 + b95f414 commit a42f799
Show file tree
Hide file tree
Showing 64 changed files with 894 additions and 305 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OWLAPY
[![Coverage](https://img.shields.io/badge/coverage-78%25-green)](https://dice-group.github.io/owlapy/usage/further_resources.html#coverage-report)
[![Pypi](https://img.shields.io/badge/pypi-1.3.0-blue)](https://pypi.org/project/owlapy/1.3.0/)
[![Docs](https://img.shields.io/badge/documentation-1.3.0-yellow)](https://dice-group.github.io/owlapy/usage/main.html)
[![Pypi](https://img.shields.io/badge/pypi-1.3.1-blue)](https://pypi.org/project/owlapy/1.3.1/)
[![Docs](https://img.shields.io/badge/documentation-1.3.1-yellow)](https://dice-group.github.io/owlapy/usage/main.html)

![OWLAPY](docs/_static/images/owlapy_logo.png)

Expand All @@ -25,11 +25,10 @@ pip3 install owlapy
```shell
# To download RDF knowledge graphs
wget https://files.dice-research.org/projects/Ontolearn/KGs.zip -O ./KGs.zip && unzip KGs.zip
pytest -p no:warnings -x # Running 102 tests takes ~ 1 min
pytest -p no:warnings -x # Running 142 tests ~ 30 secs
```

## Usage

## Examples

### Creating OWL Class Expressions
<details><summary> Click me! </summary>
Expand Down Expand Up @@ -91,7 +90,7 @@ from owlapy.static_funcs import stopJVM

ontology_path = "KGs/Family/family-benchmark_rich_background.owl"
# Available OWL Reasoners: 'HermiT', 'Pellet', 'JFact', 'Openllet'
reasoner = SyncReasoner(ontology = ontology_path, reasoner="Pellet")
sync_reasoner = SyncReasoner(ontology = ontology_path, reasoner="Pellet")
onto = OntologyManager().load_ontology(ontology_path)
# Iterate over defined owl Classes in the signature
for i in onto.classes_in_signature():
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

project = 'OWLAPY'
author = 'Ontolearn Team'
release = '1.3.0'
release = '1.3.1'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/main.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About owlapy

**Version:** owlapy 1.3.0
**Version:** owlapy 1.3.1

**GitHub repository:** [https://github.com/dice-group/owlapy](https://github.com/dice-group/owlapy)

Expand Down
45 changes: 0 additions & 45 deletions examples/comparing_adaptor_reasoners.py

This file was deleted.

51 changes: 51 additions & 0 deletions examples/ontology_engineering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from owlapy.class_expression import OWLClass
from owlapy.owl_axiom import OWLDeclarationAxiom, OWLClassAssertionAxiom
from owlapy.owl_individual import OWLNamedIndividual
from owlapy.owl_ontology_manager import OntologyManager
from owlapy.iri import IRI
from owlapy.static_funcs import download_external_files
# (1) Download the datasets if KGs does not exist.
download_external_files("https://files.dice-research.org/projects/Ontolearn/KGs.zip")
# (2) Load the father ontology using a new ontology manager.
onto = OntologyManager().load_ontology(path='file://../KGs/Family/father.owl')
# (3) Iterate over defined OWL classes, object properties.
print("OWL Classes:")
for c in onto.classes_in_signature():
print(c)
print("\nOWL Properties:")
for p in onto.properties_in_signature():
print(p)
print("\nOWL Individuals:")
for i in onto.individuals_in_signature():
print(i)
print("\nOWL Class Axioms:")
for a in onto.general_class_axioms():
print(a)
"""
@TODO: Will be implemented.
for a in onto.tbox_axioms():
print(a)
for a in onto.abox_axioms_between_individuals():
print(a)
for a in onto.abox_axioms_between_individuals_and_classes():
print(a)
"""
# (4) Create a new class (father)
father = OWLClass(IRI.create('http://example.com/father#child'))
# (5) Add a declaration axiom for this class,
onto.add_axiom(axiom=OWLDeclarationAxiom(father))
# (6) Check whether the newly defined class is in the signature.
assert father in [ c for c in onto.classes_in_signature()]
# (7) Iterate over owl individuals
print("\nOWL Individuals:")
for i in onto.individuals_in_signature():
print(i)
# (8) Create an owl individual and used it in an axiom.
cdemir = OWLNamedIndividual('http://example.com/father#cdemir')
onto.add_axiom(OWLClassAssertionAxiom(cdemir, father))
# (9) Check whether cdemir is in the signature.
assert cdemir in [ c for c in onto.individuals_in_signature()]
# (10) Save the modified ontology locally.
onto.save(path="babo.owl",rdf_format = "rdfxml")


46 changes: 0 additions & 46 deletions examples/ontology_modification.py

This file was deleted.

39 changes: 39 additions & 0 deletions examples/ontology_reasoning_retrieval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
KB = { (A subclass B), (B subclass C), (x type A) }
KB = { (A subclass B), (B subclass C), (x type A), (x type B), (x type C) }
Missing types are inferred due to subclass hierarchy.
"""
from owlapy.class_expression import OWLClass
from owlapy.owl_axiom import OWLDeclarationAxiom, OWLClassAssertionAxiom, OWLSubClassOfAxiom
from owlapy.owl_ontology_manager import OntologyManager
from owlapy.owl_individual import OWLNamedIndividual
from owlapy.iri import IRI
from owlapy.owl_reasoner import SyncReasoner
# () Define a base IRI.
base_iri = IRI(namespace="https://github.com/dice-group/owlapy#")
# () Create an empty ontology.
onto = OntologyManager().create_ontology(iri=base_iri)
# () Define classes and individuals.
A = OWLClass(iri=base_iri.get_namespace() + "A")
B = OWLClass(iri=base_iri.get_namespace() + "B")
C = OWLClass(iri=base_iri.get_namespace() + "C")
x = OWLNamedIndividual(iri=base_iri.get_namespace() + "x")
# () Add axioms.
onto.add_axiom([OWLDeclarationAxiom(A),
OWLDeclarationAxiom(B),
OWLDeclarationAxiom(C),
OWLDeclarationAxiom(x),
OWLSubClassOfAxiom(A,B),
OWLSubClassOfAxiom(B,C),
OWLClassAssertionAxiom(x,A)])
# () Save axioms [ (A subclass B), (B subclass C), (x type A) ].
onto.save("new_ontology.owl")
# () Initialize reasoner.
reasoner = SyncReasoner(ontology="new_ontology.owl", reasoner="Pellet")
# () Infer instances.
for i in reasoner.ontology.classes_in_signature():
print(f"Retrieve {i}:",end=" ")
print(" ".join( [_.str for _ in reasoner.instances(i)]))
33 changes: 33 additions & 0 deletions examples/ontology_reasoning_retrieval_agreements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from owlapy.owl_reasoner import SyncReasoner
from owlapy import OntologyManager
from owlapy.class_expression import OWLClassExpression
from typing import Dict
ontology_path = "../KGs/Family/family-benchmark_rich_background.owl"
# () Load ontology
onto = OntologyManager().load_ontology(ontology_path)

# () Initialize Reasoners
reasoners = dict()
reasoners["HermiT"] = SyncReasoner(ontology=ontology_path, reasoner="HermiT")
reasoners["Pellet"] = SyncReasoner(ontology=ontology_path, reasoner="Pellet")
reasoners["JFact"] = SyncReasoner(ontology=ontology_path, reasoner="JFact")
reasoners["Openllet"] = SyncReasoner(ontology=ontology_path, reasoner="Openllet")

def compute_agreements(owl_reasoners:Dict[str,SyncReasoner], expression: OWLClassExpression, verbose=False):
if verbose:
print(f"Computing agreements between Reasoners on {expression}...",end="\t")
retrieval_result = None
flag = False
for __, reasoner in owl_reasoners.items():
if retrieval_result:
flag = retrieval_result == {_.str for _ in reasoner.instances(expression)}
else:
retrieval_result = {_.str for _ in reasoner.instances(expression)}
if verbose:
print(f"Successful:{flag}")
return flag

# () Iterate over named classes
for c in onto.classes_in_signature():
# reasoners must agree
assert compute_agreements(reasoners, c, True)
Loading

0 comments on commit a42f799

Please sign in to comment.