Function format_solution

Source
pub fn format_solution(query: &Goal, result: &Unifiable) -> String
Expand description

Formats the results of a query for display.

For example, if the query were loves(Leonard, $Whom), and the result were loves(Leonard, Penny), then the function would return: $Whom = Penny

This function iterates through the query’s terms. For every logic variable in the query, it prints the variable’s name and the corresponding term from the result.

§Arguments

§Return

  • formatted solution

§Usage

use std::rc::Rc;
use suiron::*;

let kb = test_kb();
let query = parse_query("loves(Leonard, $Whom)").unwrap();
let q = Rc::new(query);
let sn = make_base_node(Rc::clone(&q), &kb); // solution node

if let Some(ss) = next_solution(Rc::clone(&sn)) {
    let result = q.replace_variables(&ss);
    println!("{}", format_solution(&q, &result));
}
// Prints: $Whom = Penny