Skip to content

Commit a42f799

Browse files
authored
Merge pull request #86 from dice-group/develop
New release: owlapy 1.3.1
2 parents 9a95b15 + b95f414 commit a42f799

File tree

64 files changed

+894
-305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+894
-305
lines changed

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# OWLAPY
22
[![Coverage](https://img.shields.io/badge/coverage-78%25-green)](https://dice-group.github.io/owlapy/usage/further_resources.html#coverage-report)
3-
[![Pypi](https://img.shields.io/badge/pypi-1.3.0-blue)](https://pypi.org/project/owlapy/1.3.0/)
4-
[![Docs](https://img.shields.io/badge/documentation-1.3.0-yellow)](https://dice-group.github.io/owlapy/usage/main.html)
3+
[![Pypi](https://img.shields.io/badge/pypi-1.3.1-blue)](https://pypi.org/project/owlapy/1.3.1/)
4+
[![Docs](https://img.shields.io/badge/documentation-1.3.1-yellow)](https://dice-group.github.io/owlapy/usage/main.html)
55

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

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

31-
## Usage
32-
31+
## Examples
3332

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

9291
ontology_path = "KGs/Family/family-benchmark_rich_background.owl"
9392
# Available OWL Reasoners: 'HermiT', 'Pellet', 'JFact', 'Openllet'
94-
reasoner = SyncReasoner(ontology = ontology_path, reasoner="Pellet")
93+
sync_reasoner = SyncReasoner(ontology = ontology_path, reasoner="Pellet")
9594
onto = OntologyManager().load_ontology(ontology_path)
9695
# Iterate over defined owl Classes in the signature
9796
for i in onto.classes_in_signature():

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
project = 'OWLAPY'
1515
author = 'Ontolearn Team'
16-
release = '1.3.0'
16+
release = '1.3.1'
1717

1818
# -- General configuration ---------------------------------------------------
1919
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

docs/usage/main.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# About owlapy
22

3-
**Version:** owlapy 1.3.0
3+
**Version:** owlapy 1.3.1
44

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

examples/comparing_adaptor_reasoners.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/ontology_engineering.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from owlapy.class_expression import OWLClass
2+
from owlapy.owl_axiom import OWLDeclarationAxiom, OWLClassAssertionAxiom
3+
from owlapy.owl_individual import OWLNamedIndividual
4+
from owlapy.owl_ontology_manager import OntologyManager
5+
from owlapy.iri import IRI
6+
from owlapy.static_funcs import download_external_files
7+
# (1) Download the datasets if KGs does not exist.
8+
download_external_files("https://files.dice-research.org/projects/Ontolearn/KGs.zip")
9+
# (2) Load the father ontology using a new ontology manager.
10+
onto = OntologyManager().load_ontology(path='file://../KGs/Family/father.owl')
11+
# (3) Iterate over defined OWL classes, object properties.
12+
print("OWL Classes:")
13+
for c in onto.classes_in_signature():
14+
print(c)
15+
print("\nOWL Properties:")
16+
for p in onto.properties_in_signature():
17+
print(p)
18+
print("\nOWL Individuals:")
19+
for i in onto.individuals_in_signature():
20+
print(i)
21+
print("\nOWL Class Axioms:")
22+
for a in onto.general_class_axioms():
23+
print(a)
24+
"""
25+
@TODO: Will be implemented.
26+
for a in onto.tbox_axioms():
27+
print(a)
28+
for a in onto.abox_axioms_between_individuals():
29+
print(a)
30+
for a in onto.abox_axioms_between_individuals_and_classes():
31+
print(a)
32+
"""
33+
# (4) Create a new class (father)
34+
father = OWLClass(IRI.create('http://example.com/father#child'))
35+
# (5) Add a declaration axiom for this class,
36+
onto.add_axiom(axiom=OWLDeclarationAxiom(father))
37+
# (6) Check whether the newly defined class is in the signature.
38+
assert father in [ c for c in onto.classes_in_signature()]
39+
# (7) Iterate over owl individuals
40+
print("\nOWL Individuals:")
41+
for i in onto.individuals_in_signature():
42+
print(i)
43+
# (8) Create an owl individual and used it in an axiom.
44+
cdemir = OWLNamedIndividual('http://example.com/father#cdemir')
45+
onto.add_axiom(OWLClassAssertionAxiom(cdemir, father))
46+
# (9) Check whether cdemir is in the signature.
47+
assert cdemir in [ c for c in onto.individuals_in_signature()]
48+
# (10) Save the modified ontology locally.
49+
onto.save(path="babo.owl",rdf_format = "rdfxml")
50+
51+

examples/ontology_modification.py

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
3+
KB = { (A subclass B), (B subclass C), (x type A) }
4+
5+
KB = { (A subclass B), (B subclass C), (x type A), (x type B), (x type C) }
6+
7+
Missing types are inferred due to subclass hierarchy.
8+
"""
9+
from owlapy.class_expression import OWLClass
10+
from owlapy.owl_axiom import OWLDeclarationAxiom, OWLClassAssertionAxiom, OWLSubClassOfAxiom
11+
from owlapy.owl_ontology_manager import OntologyManager
12+
from owlapy.owl_individual import OWLNamedIndividual
13+
from owlapy.iri import IRI
14+
from owlapy.owl_reasoner import SyncReasoner
15+
# () Define a base IRI.
16+
base_iri = IRI(namespace="https://github.com/dice-group/owlapy#")
17+
# () Create an empty ontology.
18+
onto = OntologyManager().create_ontology(iri=base_iri)
19+
# () Define classes and individuals.
20+
A = OWLClass(iri=base_iri.get_namespace() + "A")
21+
B = OWLClass(iri=base_iri.get_namespace() + "B")
22+
C = OWLClass(iri=base_iri.get_namespace() + "C")
23+
x = OWLNamedIndividual(iri=base_iri.get_namespace() + "x")
24+
# () Add axioms.
25+
onto.add_axiom([OWLDeclarationAxiom(A),
26+
OWLDeclarationAxiom(B),
27+
OWLDeclarationAxiom(C),
28+
OWLDeclarationAxiom(x),
29+
OWLSubClassOfAxiom(A,B),
30+
OWLSubClassOfAxiom(B,C),
31+
OWLClassAssertionAxiom(x,A)])
32+
# () Save axioms [ (A subclass B), (B subclass C), (x type A) ].
33+
onto.save("new_ontology.owl")
34+
# () Initialize reasoner.
35+
reasoner = SyncReasoner(ontology="new_ontology.owl", reasoner="Pellet")
36+
# () Infer instances.
37+
for i in reasoner.ontology.classes_in_signature():
38+
print(f"Retrieve {i}:",end=" ")
39+
print(" ".join( [_.str for _ in reasoner.instances(i)]))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from owlapy.owl_reasoner import SyncReasoner
2+
from owlapy import OntologyManager
3+
from owlapy.class_expression import OWLClassExpression
4+
from typing import Dict
5+
ontology_path = "../KGs/Family/family-benchmark_rich_background.owl"
6+
# () Load ontology
7+
onto = OntologyManager().load_ontology(ontology_path)
8+
9+
# () Initialize Reasoners
10+
reasoners = dict()
11+
reasoners["HermiT"] = SyncReasoner(ontology=ontology_path, reasoner="HermiT")
12+
reasoners["Pellet"] = SyncReasoner(ontology=ontology_path, reasoner="Pellet")
13+
reasoners["JFact"] = SyncReasoner(ontology=ontology_path, reasoner="JFact")
14+
reasoners["Openllet"] = SyncReasoner(ontology=ontology_path, reasoner="Openllet")
15+
16+
def compute_agreements(owl_reasoners:Dict[str,SyncReasoner], expression: OWLClassExpression, verbose=False):
17+
if verbose:
18+
print(f"Computing agreements between Reasoners on {expression}...",end="\t")
19+
retrieval_result = None
20+
flag = False
21+
for __, reasoner in owl_reasoners.items():
22+
if retrieval_result:
23+
flag = retrieval_result == {_.str for _ in reasoner.instances(expression)}
24+
else:
25+
retrieval_result = {_.str for _ in reasoner.instances(expression)}
26+
if verbose:
27+
print(f"Successful:{flag}")
28+
return flag
29+
30+
# () Iterate over named classes
31+
for c in onto.classes_in_signature():
32+
# reasoners must agree
33+
assert compute_agreements(reasoners, c, True)

0 commit comments

Comments
 (0)