-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from dice-group/develop
New release: owlapy 1.3.1
- Loading branch information
Showing
64 changed files
with
894 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.