From 32198ffea352d7ff4c77c30fc729359e8617407e Mon Sep 17 00:00:00 2001 From: Caglar Demir Date: Wed, 18 Sep 2024 13:10:24 +0200 Subject: [PATCH] Initial test for alc retrieval on father with hermit started --- tests/test_reasoner_alc_father_ontology.py | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/test_reasoner_alc_father_ontology.py diff --git a/tests/test_reasoner_alc_father_ontology.py b/tests/test_reasoner_alc_father_ontology.py new file mode 100644 index 00000000..a702545b --- /dev/null +++ b/tests/test_reasoner_alc_father_ontology.py @@ -0,0 +1,45 @@ +from owlapy.owl_reasoner import SyncReasoner +from owlapy.class_expression import OWLClass, OWLObjectSomeValuesFrom +from owlapy.owl_individual import OWLNamedIndividual +from owlapy.iri import IRI +from owlapy.owl_property import OWLObjectProperty + + +class TestHermitFather: + def test_readme(self): + + ontology_path = "KGs/Family/father.owl" + hermit = SyncReasoner(ontology=ontology_path, reasoner="HermiT") + + # Thing + thing = OWLClass(IRI('http://www.w3.org/2002/07/owl#', 'Thing')) + # Person OWL Class + person = eval("OWLClass(IRI('http://example.com/father#', 'person'))") + # Female OWL CLass + female = eval("OWLClass(IRI('http://example.com/father#', 'female'))") + # hasChild object property + hasChild = eval("OWLObjectProperty(IRI('http://example.com/father#', 'hasChild'))") + + # Things + assert hermit.instances(thing) == eval( + "{OWLNamedIndividual(IRI('http://example.com/father#', 'anna')), OWLNamedIndividual(IRI('http://example.com/father#', 'martin')), OWLNamedIndividual(IRI('http://example.com/father#', 'heinz')), OWLNamedIndividual(IRI('http://example.com/father#', 'stefan')), OWLNamedIndividual(IRI('http://example.com/father#', 'michelle')), OWLNamedIndividual(IRI('http://example.com/father#', 'markus'))}") + + # hasChild a thing. + assert hermit.instances(OWLObjectSomeValuesFrom(property=hasChild, filler=thing)) == eval( + "{OWLNamedIndividual(IRI('http://example.com/father#', 'markus')), OWLNamedIndividual(IRI('http://example.com/father#', 'martin')), OWLNamedIndividual(IRI('http://example.com/father#', 'stefan')), OWLNamedIndividual(IRI('http://example.com/father#', 'anna'))}") + + # hasChild a person. + assert hermit.instances(OWLObjectSomeValuesFrom(property=hasChild, filler=person)) == eval( + "{OWLNamedIndividual(IRI('http://example.com/father#', 'markus')), OWLNamedIndividual(IRI('http://example.com/father#', 'martin')), OWLNamedIndividual(IRI('http://example.com/father#', 'stefan')), OWLNamedIndividual(IRI('http://example.com/father#', 'anna'))}") + + # hasChild a female. + assert hermit.instances(OWLObjectSomeValuesFrom(property=hasChild, filler=female)) == eval( + "{OWLNamedIndividual(IRI('http://example.com/father#', 'markus'))}") + # Question: hasChild something that hasChild a female. + # Answer: stefan + # (stefan haschild markus) and markus haschild anna + assert hermit.instances(OWLObjectSomeValuesFrom(property=hasChild, + filler=OWLObjectSomeValuesFrom(property=hasChild, + filler=female))) == eval( + "{OWLNamedIndividual(IRI('http://example.com/father#', 'stefan'))}") +