engine.rete_engine¶
RETE engine facade for per-context triple entailment and truth maintenance.
Attributes¶
Classes¶
Read-only callback context for one fired rule activation. |
|
Explicit configuration for one RETE engine context. |
|
Public engine facade for fixed-point triple entailment within one context. |
Module Contents¶
- engine.rete_engine.LiteralSubjectPolicy¶
- engine.rete_engine.PredicateTermPolicy¶
- class engine.rete_engine.EngineCallbackContext¶
Bases:
engine.builtins.RuleContextRead-only callback context for one fired rule activation.
- context: axiom.common.ContextIdentifier | None¶
- rule_id: Any¶
- bindings: collections.abc.Mapping[str, rdflib.term.Node]¶
- premises: tuple[axiom.common.Triple, Ellipsis]¶
- class engine.rete_engine.RETEEngineConfig¶
Explicit configuration for one RETE engine context.
- context: axiom.common.ContextIdentifier¶
- builtins: engine.builtins.Builtins¶
- derivation_logger: engine.derivation.DerivationLogger¶
- contradiction_recorder: engine.derivation.ContradictionRecorder¶
- literal_subject_policy: LiteralSubjectPolicy¶
- predicate_term_policy: PredicateTermPolicy¶
- class engine.rete_engine.RETEEngine(config: RETEEngineConfig, rules: collections.abc.Iterable[engine.rules.Rule])¶
Public engine facade for fixed-point triple entailment within one context.
The facade represents the direct implementation boundary: triple-oriented rule execution, dependency-aware retraction, optional derivation logging, and warm-start over an existing context. User-facing proof reconstruction is layered on top of derivation records rather than being the engine’s execution format.
The engine also enforces RDF 1.1 triple well-formedness for both stated and inferred triples. Literal subjects and non-IRI predicates never enter working memory or derived outputs. Callers can choose fail-fast or warning-and-skip behavior via
literal_subject_policyandpredicate_term_policyin the engine config.- config: RETEEngineConfig¶
- known_triples: set[axiom.common.Triple]¶
- materialized_triples: set[axiom.common.Triple]¶
- matcher: engine.rete.NetworkMatcher¶
- derivation_logger: engine.derivation.DerivationLogger¶
- contradiction_recorder: engine.derivation.ContradictionRecorder¶
- callbacks: collections.abc.Mapping[str, engine.builtins.CallbackHook]¶
- tms: engine.rete.TMSController¶
- working_memory: engine.rete.WorkingMemory¶
- literal_subject_policy: LiteralSubjectPolicy¶
- predicate_term_policy: PredicateTermPolicy¶
- contradiction_records(*, context: axiom.common.ContextIdentifier | None = None) tuple[engine.proof.ContradictionRecord, Ellipsis]¶
Return contradiction records, optionally filtered by context.
- add_triples(triples: collections.abc.Iterable[axiom.common.Triple]) set[axiom.common.Triple]¶
Add stated triples, saturate inference, and return newly derived triples.
Incoming triples are first checked against the engine’s RDF 1.1 triple well-formedness policies. Triples rejected under those policies are either raised as errors or warned-and-skipped before they can enter working memory or derivation outputs.
Per DR-004, this method is idempotent for triples the engine already knows. Triples already present in
known_triplesare skipped beforeregister_statedruns so that materialization round-trips through the store dispatcher do not retroactively promote derived facts to stated facts.
- retract_triples(triples: collections.abc.Iterable[axiom.common.Triple]) set[axiom.common.Triple]¶
Retract triples; return all triples that left the logical closure.
For each input triple the engine looks up the working-memory fact:
If the fact is absent, the input is skipped (idempotent for already-absent triples; a second call with the same input is a no-op).
If the fact is stated, the engine delegates to
TMSController.retract_tripleand consumes the resultingRetractionOutcome. Stated facts that also have derived justifications have only thestatedflag cleared; they remain in working memory and are NOT included in the returned set.If the fact is derived only, the engine leaves working memory unchanged and does NOT include the triple in the returned set. Callers that received this triple from a store-side removal event are expected to re-add it to the backing store under the policy documented in DR-025.
After all TMS calls finish, the engine evicts persisted partial matches that referenced the removed facts so that subsequent join passes do not produce activations grounded in retracted facts.
known_triplesandmaterialized_triplesare updated so they no longer include triples that left the logical closure; triples whose working-memory fact survived (stated-and-derived clearings, derived-only) remain in both sets.Returns the union of (a) input triples whose working-memory fact was actually removed and (b) cascade consequents removed by Mark-Verify-Sweep. Idempotence is the symmetric counterpart of the DR-004 requirement that
add_triplesis idempotent for already-known triples;BatchDispatcherrelies on this symmetry to converge cascade events without an explicit reentrancy guard.
- warmup(existing_triples: collections.abc.Iterable[axiom.common.Triple]) set[axiom.common.Triple]¶
Warm the engine from existing triples and return engine-managed deductions.