pub struct KnowledgeBase { /* private fields */ }Expand description
A set of rules, kept in salience order and compiled for execution.
A RuleEngine holds one; rules are usually added through the
engine’s add_rules_from_* methods.
Implementations§
Source§impl KnowledgeBase
impl KnowledgeBase
Sourcepub fn add_rule(&mut self, rule: Rule) -> Result<(), String>
pub fn add_rule(&mut self, rule: Rule) -> Result<(), String>
Adds a rule. Fails if a rule with the same name exists.
Sourcepub fn add_rules_from_str(&mut self, grl: &str) -> Result<usize, String>
pub fn add_rules_from_str(&mut self, grl: &str) -> Result<usize, String>
Parses GRL text and adds all of its rules. Returns how many were added. Nothing is added if any rule fails to parse or clashes with an existing name.
Sourcepub fn add_rules_from_file(
&mut self,
path: impl AsRef<Path>,
) -> Result<usize, String>
pub fn add_rules_from_file( &mut self, path: impl AsRef<Path>, ) -> Result<usize, String>
Loads all rules from a .grl file. Returns how many were added.
Sourcepub fn add_rules_from_dir(
&mut self,
dir: impl AsRef<Path>,
) -> Result<usize, String>
pub fn add_rules_from_dir( &mut self, dir: impl AsRef<Path>, ) -> Result<usize, String>
Loads all .grl files under dir, recursively, in path order.
Returns how many rules were added.
Sourcepub fn get_rules_sorted_by_salience(&self) -> Vec<&Rule>
pub fn get_rules_sorted_by_salience(&self) -> Vec<&Rule>
All rules, highest salience first; rules with equal salience in the order they were added.
Sourcepub fn rules_by_salience(&self) -> impl Iterator<Item = &Rule> + '_
pub fn rules_by_salience(&self) -> impl Iterator<Item = &Rule> + '_
Iterates rules highest salience first; rules with equal salience come in the order they were added.
Sourcepub fn remove_rule(&mut self, name: &str) -> Option<Rule>
pub fn remove_rule(&mut self, name: &str) -> Option<Rule>
Removes and returns the rule with the given name.