engine.derivation ================= .. py:module:: engine.derivation .. autoapi-nested-parse:: Engine-native derivation logging, contradiction recording, and proof reconstruction. Exceptions ---------- .. autoapisummary:: engine.derivation.ContradictionWarning engine.derivation.ContradictionDetectedError Classes ------- .. autoapisummary:: engine.derivation.DerivationLogger engine.derivation.ContradictionRecorder engine.derivation.InMemoryDerivationLogger engine.derivation.DropDerivationLogger engine.derivation.InMemoryContradictionRecorder engine.derivation.RaiseOnContradictionRecorder engine.derivation.DropContradictionRecorder engine.derivation.ExplanationReconstructor engine.derivation.DerivationProofReconstructor Functions --------- .. autoapisummary:: engine.derivation.format_contradiction_record Module Contents --------------- .. py:function:: format_contradiction_record(record: engine.proof.ContradictionRecord) -> str Format one contradiction diagnostic for logs, warnings, or exceptions. .. py:exception:: ContradictionWarning Bases: :py:obj:`UserWarning` Warning emitted when a contradiction is detected. .. py:class:: DerivationLogger Bases: :py:obj:`Protocol` Interface for sinks of engine-native derivation records. These records are engine provenance artifacts, not user-facing proof steps. .. py:method:: record(record: engine.proof.DerivationRecord) -> None Append one engine-native derivation record. .. py:method:: iter_records() -> collections.abc.Iterable[engine.proof.DerivationRecord] Yield derivation records currently held by the sink. .. py:method:: clear() -> None Remove all derivation records from the sink. .. py:class:: ContradictionRecorder Bases: :py:obj:`Protocol` Interface for sinks of engine-native contradiction records. .. py:method:: record(record: engine.proof.ContradictionRecord) -> None Append one engine-native contradiction record. .. py:method:: iter_records() -> collections.abc.Iterable[engine.proof.ContradictionRecord] Yield contradiction records currently held by the sink. .. py:method:: clear() -> None Remove all contradiction records from the sink. .. py:class:: InMemoryDerivationLogger Simple in-memory sink for engine-native derivation records. .. py:attribute:: records :type: collections.abc.MutableSequence[engine.proof.DerivationRecord] :value: [] .. py:method:: record(record: engine.proof.DerivationRecord) -> None Append one derivation record to the in-memory log. .. py:method:: iter_records() -> collections.abc.Iterable[engine.proof.DerivationRecord] Return a snapshot of all logged derivation records. .. py:method:: clear() -> None Remove all logged derivation records. .. py:class:: DropDerivationLogger Drop-all sink for derivation records (no retention). .. py:method:: record(record: engine.proof.DerivationRecord) -> None Discard ``record`` without retaining it. .. py:method:: iter_records() -> collections.abc.Iterable[engine.proof.DerivationRecord] Return an empty sequence because no records are retained. .. py:method:: clear() -> None No-op because no records are retained. .. py:class:: InMemoryContradictionRecorder Append-all sink for contradiction diagnostics (unbounded retention). When ``warn`` is true (default), each contradiction also emits :class:`ContradictionWarning` via :func:`warnings.warn`. .. py:attribute:: warn :type: bool :value: True .. py:attribute:: records :type: collections.abc.MutableSequence[engine.proof.ContradictionRecord] :value: [] .. py:method:: record(record: engine.proof.ContradictionRecord) -> None Append one contradiction record to the in-memory log. .. py:method:: iter_records() -> collections.abc.Iterable[engine.proof.ContradictionRecord] Return a snapshot of all logged contradiction records. .. py:method:: clear() -> None Remove all logged contradiction records. .. py:exception:: ContradictionDetectedError(record: engine.proof.ContradictionRecord) Bases: :py:obj:`RuntimeError` Error raised when a contradiction is detected. .. py:attribute:: record :type: engine.proof.ContradictionRecord .. py:class:: RaiseOnContradictionRecorder Append each contradiction then raise :class:`ContradictionDetectedError`. Retention is unbounded (same list semantics as :class:`InMemoryContradictionRecorder`) unless :meth:`clear` is called. .. py:attribute:: records :type: collections.abc.MutableSequence[engine.proof.ContradictionRecord] :value: [] .. py:method:: record(record: engine.proof.ContradictionRecord) -> None Append ``record`` and raise :class:`ContradictionDetectedError`. .. py:method:: iter_records() -> collections.abc.Iterable[engine.proof.ContradictionRecord] Return a snapshot of contradiction records logged before any raise. .. py:method:: clear() -> None Remove all logged contradiction records. .. py:class:: DropContradictionRecorder Discard contradiction diagnostics after optional warning (zero retention). :meth:`iter_records` is always empty—there is nothing for :meth:`~rdflib_reasoning.engine.api.RETEEngine.contradiction_records` or explanation reconstruction to read from this recorder alone. .. py:attribute:: warn :type: bool :value: True .. py:method:: record(record: engine.proof.ContradictionRecord) -> None Optionally warn about ``record`` and discard it without retention. .. py:method:: iter_records() -> collections.abc.Iterable[engine.proof.ContradictionRecord] Return an empty sequence because no records are retained. .. py:method:: clear() -> None No-op because no records are retained. .. py:class:: ExplanationReconstructor Bases: :py:obj:`Protocol` Interface for rebuilding `DirectProof` values from derivation records. .. py:method:: reconstruct(goal: engine.proof.ProofPayload, records: collections.abc.Iterable[engine.proof.DerivationRecord | engine.proof.ContradictionRecord]) -> engine.proof.DirectProof Rebuild a :class:`DirectProof` for ``goal`` from engine trace records. .. py:class:: DerivationProofReconstructor Rebuild a `DirectProof` tree from engine-native trace records. Triple goals are reconstructed from ``DerivationRecord`` values. Contradiction goals are reconstructed from ``ContradictionRecord`` values. .. py:method:: reconstruct(goal: engine.proof.ProofPayload, records: collections.abc.Iterable[engine.proof.DerivationRecord | engine.proof.ContradictionRecord]) -> engine.proof.DirectProof Build a :class:`DirectProof` tree for ``goal`` from derivation and contradiction records.