engine.rete.tms¶
Truth-maintenance support graph, working memory, and retraction control.
Classes¶
Bidirectional map tracking logical support relationships among facts. |
|
A single reason for a fact's logical support. |
|
Immutable view of a fact's TMS support state at a moment in time. |
|
Immutable record of the facts and justifications affected by a retraction. |
|
Reactive store of currently asserted facts flowing through the network. |
|
Controller for truth-maintenance bookkeeping and recursive retraction. |
Module Contents¶
- class engine.rete.tms.DependencyGraph(/, **data: Any)¶
Bases:
pydantic.BaseModelBidirectional map tracking logical support relationships among facts.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- add_support(consequent_id: str, antecedent_ids: tuple[str, Ellipsis]) None¶
Record that
consequent_idis supported byantecedent_ids.
- antecedents_of(consequent_id: str) tuple[str, Ellipsis]¶
Return sorted antecedent fact ids supporting
consequent_id.
- consequents_of(antecedent_id: str) tuple[str, Ellipsis]¶
Return sorted consequent fact ids supported by
antecedent_id.
- discard_consequent(consequent_id: str) None¶
Remove every edge that involves this fact.
Used when the fact is being swept from working memory: both the consequent-to-antecedent and antecedent-to-consequent directions of the dependency graph are cleared.
- update_consequent_edges(consequent_id: str, antecedent_ids: collections.abc.Iterable[str]) None¶
Rewrite a consequent’s antecedent edges to the given identifiers.
Used when a fact is kept after a sweep but its justification set has been trimmed: the consequent’s antecedent edges are set to exactly the union of antecedents of its surviving justifications, and reverse edges that no longer correspond to any surviving justification are discarded.
- class engine.rete.tms.Justification(/, **data: Any)¶
Bases:
pydantic.BaseModelA single reason for a fact’s logical support.
Justifications are logical support records used for future truth maintenance; they are distinct from user-facing proof nodes.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- rule_id: engine.proof.RuleId¶
- class engine.rete.tms.SupportSnapshot(/, **data: Any)¶
Bases:
pydantic.BaseModelImmutable view of a fact’s TMS support state at a moment in time.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- triple: axiom.common.Triple¶
- class engine.rete.tms.RetractionOutcome(/, **data: Any)¶
Bases:
pydantic.BaseModelImmutable record of the facts and justifications affected by a retraction.
Mark-Verify-Sweep retraction may remove facts from working memory, drop justification records, and clear the
statedflag from a fact that survives because of independent derived support. This outcome surfaces all three categories so that engine-side wiring can mirror the changes through the supported RDFLib integration path.- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- removed_triples: tuple[axiom.common.Triple, Ellipsis] = ()¶
- class engine.rete.tms.WorkingMemory(/, **data: Any)¶
Bases:
pydantic.BaseModelReactive store of currently asserted facts flowing through the network.
Working memory is an execution-time structure, not a persisted proof or derivation artifact.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- facts_by_id: dict[str, engine.rete.facts.Fact] = None¶
- fact_ids_by_triple: dict[axiom.common.Triple, str] = None¶
- add_fact(triple: axiom.common.Triple, *, stated: bool) engine.rete.facts.Fact¶
Insert or promote
triplein working memory and return its fact.
- get_fact(triple: axiom.common.Triple) engine.rete.facts.Fact | None¶
Return the working-memory fact for
triple, if present.
- has_fact(triple: axiom.common.Triple) bool¶
Return whether
tripleis currently present in working memory.
- facts() tuple[engine.rete.facts.Fact, Ellipsis]¶
Return all facts currently stored in working memory.
- remove_fact(fact_id: str) engine.rete.facts.Fact¶
Remove the working-memory entry for a fact id and return it.
Raises
KeyErrorif the fact id is not present.
- class engine.rete.tms.TMSController(/, **data: Any)¶
Bases:
pydantic.BaseModelController for truth-maintenance bookkeeping and recursive retraction.
The controller owns fact support state, dependency graph maintenance, and Mark-Verify-Sweep retraction. It deliberately does not mutate RETE matcher memory or backing RDFLib stores; callers such as
RETEEngineandRETEStorecompose those integration responsibilities around the TMS primitive.- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- working_memory: WorkingMemory = None¶
- dependency_graph: DependencyGraph = None¶
- register_stated(triples: collections.abc.Iterable[axiom.common.Triple]) tuple[engine.rete.facts.Fact, Ellipsis]¶
Add stated
triplesto working memory.
- record_derivation(triple: axiom.common.Triple, *, rule_id: engine.proof.RuleId, premises: tuple[engine.rete.facts.Fact, Ellipsis], bindings: collections.abc.Mapping[str, rdflib.term.Node], depth: int) engine.rete.facts.Fact¶
Record one derived
tripleand attach a justification frompremises.
- fact_for_triple(triple: axiom.common.Triple) engine.rete.facts.Fact | None¶
Return the working-memory fact for
triple.
- justifications_for(triple: axiom.common.Triple) tuple[Justification, Ellipsis]¶
Return justifications supporting
triple.
- justifications_for_fact_id(fact_id: str) tuple[Justification, Ellipsis]¶
Return justifications recorded for
fact_id.
- support_count(triple: axiom.common.Triple) int¶
Return the number of justifications supporting
triple.
- is_supported(triple: axiom.common.Triple) bool¶
Return whether
tripleis stated or has at least one justification.
- support_snapshot(triple: axiom.common.Triple) SupportSnapshot¶
Return an immutable view of current support state for
triple.
- would_remain_supported(triple: axiom.common.Triple, *, without_justification_id: str | None = None, without_antecedent_id: str | None = None) bool¶
Return whether
triplewould remain supported after removing one support edge.
- transitively_supported(triple: axiom.common.Triple) bool¶
Return whether every justification chain for
tripleis fully grounded.
- dependents_of(triple: axiom.common.Triple) tuple[str, Ellipsis]¶
Return direct consequent fact ids that depend on
triple.
- transitive_dependents_of(triple: axiom.common.Triple) tuple[str, Ellipsis]¶
Return all transitive consequent fact ids that depend on
triple.
- retract_triple(triple: axiom.common.Triple) RetractionOutcome¶
Retract a stated triple using Mark-Verify-Sweep over support paths.
Behavior follows the usual JTMS support rules for this controller: stated facts remain supported regardless of whether they also have derived justifications; derived facts are removed only when they have no remaining valid justifications; silent justifications count the same as visible ones for support.
If the triple is unknown, the call is a no-op and an empty outcome is returned.
If the matching fact is non-stated (derived only),
ValueErroris raised. Direct retraction of derived facts violates the invariant that derived facts are removed iff their justification set becomes empty; only stated retraction is exposed at this layer.If the fact is stated and has at least one justification, the
statedflag is cleared. The fact remains present, supported by its derived justifications, and no cascade is performed.If the fact is stated and has no justifications, the fact is removed and Mark-Verify-Sweep removes any transitive dependents whose remaining justifications cannot be grounded outside the swept set.
The method is atomic: the verify fixed point completes before any mutation occurs, so the call either commits the full sweep or makes no mutations at all.
This method updates only working memory, the justification table, and the dependency graph. It does not update the RETE alpha/beta network, the agenda, or any backing RDF store; callers that embed this controller in a full engine must apply matching removals there separately.