Skip to content

Commit 9d3e26d

Browse files
authored
Merge pull request #202 from dice-group/update-readme-contrastive-example
Update README with contrastive explanation example
2 parents a5ccd4b + 1747a87 commit 9d3e26d

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,41 @@ justifications = reasoner.create_axiom_justifications(axiom)
388388
</details>
389389

390390

391+
### Get Contrastive Explanations
392+
393+
<details><summary> Click me!</summary>
394+
395+
```python
396+
from owlapy import manchester_to_owl_expression
397+
from owlapy.iri import IRI
398+
from owlapy.owl_individual import OWLNamedIndividual
399+
from owlapy.owl_ontology import SyncOntology
400+
from owlapy.owl_reasoner import SyncReasoner
401+
402+
# --- Load ontology and reasoner ---
403+
ontology = SyncOntology("../KGs/Family/family.owl")
404+
reasoner = SyncReasoner(ontology, reasoner="HermiT")
405+
406+
# --- Define class expression ---
407+
class_expr = manchester_to_owl_expression(
408+
"Sister and (hasSibling some (married some (hasChild some Grandchild)))",
409+
"http://www.benchmark.org/family#"
410+
)
411+
412+
# --- Define individuals ---
413+
fact = OWLNamedIndividual(IRI.create("http://www.benchmark.org/family#F9F143"))
414+
foil = OWLNamedIndividual(IRI.create("http://www.benchmark.org/family#F9M161"))
415+
416+
# --- Get contrastive explanation ---
417+
result = reasoner.get_contrastive_explanation(class_expr, fact, foil)
418+
419+
# --- Print results ---
420+
for k in ["common", "different", "conflict"]:
421+
print(f"{k.capitalize()} axioms: {result[k]}")
422+
```
423+
</details>
424+
425+
391426
### Class expression simplification
392427

393428
<details><summary> Click me!</summary>

0 commit comments

Comments
 (0)