Inspect a ProofΒΆ

Attach an in-memory derivation logger when you need to reconstruct a DirectProof for an inferred triple.

from dataclasses import replace

from rdflib_reasoning.engine import (
    RDFS_RETE_MATERIALIZED,
    DerivationProofReconstructor,
    InMemoryDerivationLogger,
    TripleFact,
    render_proof_markdown,
)

logger = InMemoryDerivationLogger()
spec = replace(
    RDFS_RETE_MATERIALIZED,
    derivation_logger_factory=lambda _context: logger,
)

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

# Add asserted triples, then choose the inferred triple you want to explain.
goal = TripleFact(context=graph.identifier, triple=(subject, predicate, object_))
proof = DerivationProofReconstructor().reconstruct(goal, logger.records)

print(render_proof_markdown(proof, namespace_manager=graph.namespace_manager))

The proof reconstructor works from derivation records. It is not a graph.explain(...) shortcut; callers choose the goal and supply the derivation records they want to inspect.

For rendered examples, see the RDFS inference tutorial, OWL 2 RL inference tutorial, and proof reconstruction tutorial. For API details, see engine.derivation and engine.proof_rendering.