Enable Contradiction DiagnosticsΒΆ

Extend a reasoner specification with contradiction rules when you want diagnostic events for inconsistent patterns. Contradiction rules emit records; they do not materialize ordinary triples.

from dataclasses import replace

from rdflib_reasoning.engine import (
    OWL2_RL_CONTRADICTION_RULES,
    RDFS_RETE_MATERIALIZED,
    InMemoryContradictionRecorder,
)

recorder = InMemoryContradictionRecorder(warn=False)
spec = replace(
    RDFS_RETE_MATERIALIZED,
    contradiction_recorder_factory=lambda _context: recorder,
).extend(more_rules=OWL2_RL_CONTRADICTION_RULES)

dataset = spec.dataset()
graph = dataset.default_graph

# Add triples that may trigger contradiction rules.
records = recorder.records

Use RaiseOnContradictionRecorder when contradictions should raise after being recorded, InMemoryContradictionRecorder when callers should inspect records after graph updates, and DropContradictionRecorder when retention is not needed.

For a complete walkthrough, see the contradiction rules tutorial. For API details, see engine.derivation and engine.rulesets.owl2_rl_contradictions.