Skip to main content

Module rule_dependency

Module rule_dependency 

Source
Expand description

Rule Dependency Graph

Before executing inference, rules must be evaluated in a well-defined order determined by their interdependencies. This module builds a directed dependency graph over rule IDs and computes a topological evaluation schedule so that every rule is processed only after the rules it depends upon have already been applied.

§Dependency types

VariantMeaning
DependencyType::UsesConclusionThe head of one rule appears in the body of another.
DependencyType::SharesBodyTwo rules share at least one body predicate.
DependencyType::NegationA rule uses the negation of another rule’s conclusion.
DependencyType::SubsumptionOne rule’s conclusion is subsumed by another.

§Examples

use ipfrs_tensorlogic::rule_dependency::{
    DependencyType, EvaluationSchedule, RuleDependencyGraph,
};

let mut g = RuleDependencyGraph::new();
g.add_rule("base").expect("example: should succeed in docs");
g.add_rule("derived").expect("example: should succeed in docs");
g.add_dependency("derived", "base", DependencyType::UsesConclusion).expect("example: should succeed in docs");

let order = g.topological_sort().expect("example: should succeed in docs");
assert_eq!(order, vec!["base".to_string(), "derived".to_string()]);

let sched = EvaluationSchedule::build(&g).expect("example: should succeed in docs");
assert_eq!(sched.layer_count(), 2);
assert_eq!(sched.total_rules(), 2);

Structs§

EvaluationSchedule
A layered evaluation schedule derived from a RuleDependencyGraph.
RuleDependency
A directed edge in the rule dependency graph.
RuleDependencyGraph
A directed graph that records dependencies between rules and can derive a safe topological evaluation order.
RuleId
A newtype wrapping a String that uniquely identifies a rule.

Enums§

DepError
Errors produced by RuleDependencyGraph and EvaluationSchedule.
DependencyType
Characterises the semantic relationship between two rules in the dependency graph.