From 1747a875530cd71c489bbb5d0e7dd727ccad918a Mon Sep 17 00:00:00 2001 From: Tiwari Date: Tue, 7 Apr 2026 15:15:12 +0200 Subject: [PATCH] Update README with contrastive explanation example --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 13b9996c..e31d6973 100644 --- a/README.md +++ b/README.md @@ -388,6 +388,41 @@ justifications = reasoner.create_axiom_justifications(axiom) +### Get Contrastive Explanations + +
Click me! + +```python +from owlapy import manchester_to_owl_expression +from owlapy.iri import IRI +from owlapy.owl_individual import OWLNamedIndividual +from owlapy.owl_ontology import SyncOntology +from owlapy.owl_reasoner import SyncReasoner + +# --- Load ontology and reasoner --- +ontology = SyncOntology("../KGs/Family/family.owl") +reasoner = SyncReasoner(ontology, reasoner="HermiT") + +# --- Define class expression --- +class_expr = manchester_to_owl_expression( + "Sister and (hasSibling some (married some (hasChild some Grandchild)))", + "http://www.benchmark.org/family#" +) + +# --- Define individuals --- +fact = OWLNamedIndividual(IRI.create("http://www.benchmark.org/family#F9F143")) +foil = OWLNamedIndividual(IRI.create("http://www.benchmark.org/family#F9M161")) + +# --- Get contrastive explanation --- +result = reasoner.get_contrastive_explanation(class_expr, fact, foil) + +# --- Print results --- +for k in ["common", "different", "conflict"]: + print(f"{k.capitalize()} axioms: {result[k]}") +``` +
+ + ### Class expression simplification
Click me!