IBISController

Struct IBISController 

Source
pub struct IBISController { /* private fields */ }
Expand description

Controls the IBIS dialogue system.

Implementations§

Source§

impl IBISController

Implementation of methods for the IBISController struct.

Source

pub fn new( domain: Domain, database: TravelDB, grammar: SimpleGenGrammar, ) -> Self

Creates a new IBISController.

§Arguments
  • domain - The domain knowledge.
  • database - The travel database.
  • grammar - The grammar for dialogue.
Source

pub fn with_input_handler( domain: Domain, database: TravelDB, grammar: SimpleGenGrammar, input_handler: Box<dyn InputHandler>, ) -> Self

Examples found in repository?
examples/travel.rs (line 96)
6fn main() {
7    // Initialize zero-place predicates
8    let preds0 = HashSet::from(["return".to_string(), "need-visa".to_string()]);
9    
10    // Initialize one-place predicates with their sorts
11    let preds1 = HashMap::from([
12        ("price".to_string(), "int".to_string()),
13        ("how".to_string(), "means".to_string()),
14        ("dest_city".to_string(), "city".to_string()),
15        ("depart_city".to_string(), "city".to_string()),
16        ("depart_day".to_string(), "day".to_string()),
17        ("class".to_string(), "flight_class".to_string()),
18        ("return_day".to_string(), "day".to_string()),
19    ]);
20    
21    // Initialize sorts and their individuals
22    let sorts = HashMap::from([
23        (
24            "means".to_string(),
25            HashSet::from(["plane".to_string(), "train".to_string()]),
26        ),
27        (
28            "city".to_string(),
29            HashSet::from(["paris".to_string(), "london".to_string(), "berlin".to_string()]),
30        ),
31        (
32            "day".to_string(),
33            HashSet::from(["today".to_string(), "tomorrow".to_string()]),
34        ),
35        (
36            "flight_class".to_string(),
37            HashSet::from(["first".to_string(), "second".to_string()]),
38        ),
39    ]);
40    
41    // Create the domain
42    let mut domain = Domain::new(preds0, preds1, sorts);
43
44    // Define a plan for price queries
45    let plan = vec![
46        "Findout('?x.how(x)')".to_string(),
47        "Findout('?x.dest_city(x)')".to_string(),
48        "Findout('?x.depart_city(x)')".to_string(),
49        "Findout('?x.depart_day(x)')".to_string(),
50        "Findout('?x.class(x)')".to_string(),
51        "Findout('?return()')".to_string(),
52        "If('?return()', ['Findout(?x.return_day(x))'], [])".to_string(),
53        "ConsultDB('?x.price(x)')".to_string(),
54    ];
55    domain.add_plan(Question::new("?x.price(x)").unwrap(), plan);
56
57    // Initialize the travel database
58    let mut database = TravelDB::new();
59    database.add_entry(HashMap::from([
60        ("price".to_string(), "232".to_string()),
61        ("from".to_string(), "berlin".to_string()),
62        ("to".to_string(), "paris".to_string()),
63        ("day".to_string(), "today".to_string()),
64    ]));
65    database.add_entry(HashMap::from([
66        ("price".to_string(), "345".to_string()),
67        ("from".to_string(), "paris".to_string()),
68        ("to".to_string(), "london".to_string()),
69        ("day".to_string(), "today".to_string()),
70    ]));
71
72    // Initialize the grammar
73    let mut grammar = SimpleGenGrammar::new();
74    grammar.add_form("Ask('?x.how(x)')", "How do you want to travel?");
75    grammar.add_form("Ask('?x.dest_city(x)')", "Where do you want to go?");
76    grammar.add_form("Ask('?x.depart_city(x)')", "From where are you leaving?");
77    grammar.add_form("Ask('?x.depart_day(x)')", "When do you want to leave?");
78    grammar.add_form("Ask('?x.return_day(x)')", "When do you want to return?");
79    grammar.add_form("Ask('?x.class(x)')", "First or second class?");
80    grammar.add_form("Ask('?return()')", "Do you want a return ticket?");
81
82    // Create demo inputs for non-interactive testing
83    let demo_inputs = vec![
84        "I want to go to paris".to_string(),
85        "train".to_string(),
86        "berlin".to_string(),
87        "today".to_string(),
88        "first".to_string(),
89        "yes".to_string(),
90        "tomorrow".to_string(),
91        "quit".to_string(),
92    ];
93    
94    // Create the IBIS controller with demo input handler
95    let demo_handler = isu::DemoInputHandler::new(demo_inputs);
96    let mut ibis = isu::IBISController::with_input_handler(domain, database, grammar, Box::new(demo_handler));
97    
98    println!("Starting IBIS Travel Dialogue System (Demo Mode)...");
99    println!("Simulating user interaction with predefined inputs:");
100    println!();
101    
102    // Run the demo
103    ibis.run();
104}
Source§

impl IBISController

Additional implementation to make IBISController usable

Source

pub fn run(&mut self)

Runs the dialogue manager (public interface)

Examples found in repository?
examples/travel.rs (line 103)
6fn main() {
7    // Initialize zero-place predicates
8    let preds0 = HashSet::from(["return".to_string(), "need-visa".to_string()]);
9    
10    // Initialize one-place predicates with their sorts
11    let preds1 = HashMap::from([
12        ("price".to_string(), "int".to_string()),
13        ("how".to_string(), "means".to_string()),
14        ("dest_city".to_string(), "city".to_string()),
15        ("depart_city".to_string(), "city".to_string()),
16        ("depart_day".to_string(), "day".to_string()),
17        ("class".to_string(), "flight_class".to_string()),
18        ("return_day".to_string(), "day".to_string()),
19    ]);
20    
21    // Initialize sorts and their individuals
22    let sorts = HashMap::from([
23        (
24            "means".to_string(),
25            HashSet::from(["plane".to_string(), "train".to_string()]),
26        ),
27        (
28            "city".to_string(),
29            HashSet::from(["paris".to_string(), "london".to_string(), "berlin".to_string()]),
30        ),
31        (
32            "day".to_string(),
33            HashSet::from(["today".to_string(), "tomorrow".to_string()]),
34        ),
35        (
36            "flight_class".to_string(),
37            HashSet::from(["first".to_string(), "second".to_string()]),
38        ),
39    ]);
40    
41    // Create the domain
42    let mut domain = Domain::new(preds0, preds1, sorts);
43
44    // Define a plan for price queries
45    let plan = vec![
46        "Findout('?x.how(x)')".to_string(),
47        "Findout('?x.dest_city(x)')".to_string(),
48        "Findout('?x.depart_city(x)')".to_string(),
49        "Findout('?x.depart_day(x)')".to_string(),
50        "Findout('?x.class(x)')".to_string(),
51        "Findout('?return()')".to_string(),
52        "If('?return()', ['Findout(?x.return_day(x))'], [])".to_string(),
53        "ConsultDB('?x.price(x)')".to_string(),
54    ];
55    domain.add_plan(Question::new("?x.price(x)").unwrap(), plan);
56
57    // Initialize the travel database
58    let mut database = TravelDB::new();
59    database.add_entry(HashMap::from([
60        ("price".to_string(), "232".to_string()),
61        ("from".to_string(), "berlin".to_string()),
62        ("to".to_string(), "paris".to_string()),
63        ("day".to_string(), "today".to_string()),
64    ]));
65    database.add_entry(HashMap::from([
66        ("price".to_string(), "345".to_string()),
67        ("from".to_string(), "paris".to_string()),
68        ("to".to_string(), "london".to_string()),
69        ("day".to_string(), "today".to_string()),
70    ]));
71
72    // Initialize the grammar
73    let mut grammar = SimpleGenGrammar::new();
74    grammar.add_form("Ask('?x.how(x)')", "How do you want to travel?");
75    grammar.add_form("Ask('?x.dest_city(x)')", "Where do you want to go?");
76    grammar.add_form("Ask('?x.depart_city(x)')", "From where are you leaving?");
77    grammar.add_form("Ask('?x.depart_day(x)')", "When do you want to leave?");
78    grammar.add_form("Ask('?x.return_day(x)')", "When do you want to return?");
79    grammar.add_form("Ask('?x.class(x)')", "First or second class?");
80    grammar.add_form("Ask('?return()')", "Do you want a return ticket?");
81
82    // Create demo inputs for non-interactive testing
83    let demo_inputs = vec![
84        "I want to go to paris".to_string(),
85        "train".to_string(),
86        "berlin".to_string(),
87        "today".to_string(),
88        "first".to_string(),
89        "yes".to_string(),
90        "tomorrow".to_string(),
91        "quit".to_string(),
92    ];
93    
94    // Create the IBIS controller with demo input handler
95    let demo_handler = isu::DemoInputHandler::new(demo_inputs);
96    let mut ibis = isu::IBISController::with_input_handler(domain, database, grammar, Box::new(demo_handler));
97    
98    println!("Starting IBIS Travel Dialogue System (Demo Mode)...");
99    println!("Simulating user interaction with predefined inputs:");
100    println!();
101    
102    // Run the demo
103    ibis.run();
104}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.