pub fn next_solution<'a>(
sn: Rc<RefCell<SolutionNode<'a>>>,
) -> Option<Rc<SubstitutionSet<'a>>>
Expand description
Finds the first and next solutions of the given solution node.
This method fetches facts and rules from the knowledge base,
and attempts to unify (match) each fact or rule head with the goal.
When unification succeeds, if the rule has no body (ie. it is a fact),
the method returns the updated substitution set.
If there is a body, the method gets its solution node (child node)
and attempts to solve that.
If a fact or rule fails to unify, the method will fetch the next fact/rule until the relevant predicate in the knowledge base has been exhausted. In such a case, the method returns None to indicate failure.
ยงUsage
use std::rc::Rc;
use std::cell::RefCell;
use suiron::*;
let kb = test_kb();
// Whom does Leonard love?
// Make a query and a solution node.
let query = parse_query("loves(Leonard, $Whom)").unwrap();
let q = Rc::new(query);
let solution_node = make_base_node(Rc::clone(&q), &kb);
// Get a solution.
match next_solution(solution_node) {
Some(ss) => {
let result = q.replace_variables(&ss);
println!("{}", result);
},
None => { println!("No."); },
}
// Prints: loves(Leonard, Penny)