pub struct IBISController { /* private fields */ }Expand description
Controls the IBIS dialogue system.
Implementations§
Source§impl IBISController
Implementation of methods for the IBISController struct.
impl IBISController
Implementation of methods for the IBISController struct.
Sourcepub fn new(
domain: Domain,
database: TravelDB,
grammar: SimpleGenGrammar,
) -> Self
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.
Sourcepub fn with_input_handler(
domain: Domain,
database: TravelDB,
grammar: SimpleGenGrammar,
input_handler: Box<dyn InputHandler>,
) -> Self
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
impl IBISController
Additional implementation to make IBISController usable
Sourcepub fn run(&mut self)
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§
impl Freeze for IBISController
impl !RefUnwindSafe for IBISController
impl !Send for IBISController
impl !Sync for IBISController
impl Unpin for IBISController
impl UnsafeUnpin for IBISController
impl !UnwindSafe for IBISController
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