pub struct Rule {
pub head: Unifiable,
pub body: Goal,
}
Expand description
Fields§
§head: Unifiable
§body: Goal
Implementations§
Source§impl Rule
impl Rule
Sourcepub fn key(&self) -> String
pub fn key(&self) -> String
Creates a key (predicate name) for indexing into the knowledge base.
The name of a predicate consists of its functor and its arity,
separated by a slash. For example, for the fact
loves(Chandler, Monica)
, the functor is loves
and the arity
is 2, therefore the name of the predicate is loves/2
.
§Arguments
self
§Return
key
- String
§Usage
use suiron::*;
let query = parse_query("parse($In, $Out, $ErrIn, $ErrOut)");
match query {
Ok(q) => { println!("{}", q.key()); },
Err(msg) => { println!("{}", msg); },
}
// Prints: parse/4
Sourcepub fn get_body(&self) -> Goal
pub fn get_body(&self) -> Goal
Returns the body of this rule, which is a goal.
§Arguments
self
§Return
body
- (Goal)
§Usage
use suiron::*;
clear_id();
let kb = test_kb();
// Get grandfather rule.
let rule = get_rule(&kb, "grandfather/2", 0);
let body = rule.get_body();
println!("{}", body); // father($X_1, $Z_3), father($Z_3, $Y_2)
Sourcepub fn recreate_variables(self, recreated_vars: &mut VarMap) -> Rule
pub fn recreate_variables(self, recreated_vars: &mut VarMap) -> Rule
The scope of a logic variable is the rule or goal in which it is defined.
When the inference algorithm tries to solve a goal, it calls this method to ensure that the variables are unique.
§Argument
self
recreated_vars
- logic variables already recreated
§Return
Rule
§Usage
use suiron::*;
clear_id();
match parse_rule("parent($X, $Y) :- mother($X, $Y).") {
Ok(rule) => {
let mut var_map = VarMap::new();
let rule = rule.recreate_variables(&mut var_map);
println!("{}", rule);
},
Err(msg) => { println!("{}", msg); },
}
// Prints: parent($X_1, $Y_2) :- mother($X_1, $Y_2).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Rule
impl RefUnwindSafe for Rule
impl Send for Rule
impl Sync for Rule
impl Unpin for Rule
impl UnwindSafe for Rule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more