pub struct NetworkActiveKnowledgeBase { /* private fields */ }Expand description
An active knowledge base that communicates with a remote target via network
Implementations§
Source§impl NetworkActiveKnowledgeBase
impl NetworkActiveKnowledgeBase
Sourcepub fn new(target_host: String, target_port: u16, timeout: Duration) -> Self
pub fn new(target_host: String, target_port: u16, timeout: Duration) -> Self
Creates a new network knowledge base
§Arguments
target_host- Hostname or IP address of the targettarget_port- Port number of the target servicetimeout- Socket timeout duration
Examples found in repository?
examples/network_custom_kb.rs (line 17)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("=== Network Custom KB (ATM) Example ===\n");
14
15 // Expects an independent ATM server running
16 // (see examples/custom_kb_server.rs).
17 let kb = NetworkActiveKnowledgeBase::new("127.0.0.1".to_string(), 3001, Duration::from_secs(5));
18
19 let vocabulary = vec![
20 "INSERT_CARD".to_string(),
21 "ENTER_PIN".to_string(),
22 "REQUEST_WITHDRAW".to_string(),
23 "EJECT_CARD".to_string(),
24 "TIMEOUT".to_string(),
25 ];
26
27 println!("Target Host: {}", kb.target_host());
28 println!("Target Port: {}\n", kb.target_port());
29
30 let kb: Arc<Mutex<dyn KnowledgeBaseTrait>> = Arc::new(Mutex::new(kb));
31 let mut learner = LSTAR::new(vocabulary, kb, 8, None, None);
32
33 match learner.learn() {
34 Ok(automata) => {
35 println!("\n=== Learned ATM Automaton from Network Target ===\n");
36 println!("{}", automata.build_dot_code());
37 println!(
38 "\nStates: {}\nTransitions: {}",
39 automata.get_states().len(),
40 automata.transitions.len()
41 );
42 }
43 Err(e) => {
44 eprintln!("Learning error: {}", e);
45 println!("\nTo run this example with a real connection:");
46 println!(" 1. Start ATM server: cargo run --example custom_kb_server");
47 println!(" 2. Run this example again: cargo run --example network_custom_kb");
48 }
49 }
50
51 Ok(())
52}More examples
examples/network_kb.rs (line 14)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10 println!("=== Network Active Knowledge Base Example ===\n");
11
12 // This example expects an independent coffee server running
13 // (see examples/coffee_server.rs).
14 let kb = NetworkActiveKnowledgeBase::new("127.0.0.1".to_string(), 3000, Duration::from_secs(5));
15
16 // Define input vocabulary
17 let vocabulary = vec![
18 "REFILL_WATER".to_string(),
19 "REFILL_COFFEE".to_string(),
20 "PRESS_BUTTON_A".to_string(),
21 "PRESS_BUTTON_B".to_string(),
22 "PRESS_BUTTON_C".to_string(),
23 ];
24
25 println!("Target Host: {}", kb.target_host());
26 println!("Target Port: {}\n", kb.target_port());
27
28 let kb: Arc<Mutex<dyn KnowledgeBaseTrait>> = Arc::new(Mutex::new(kb));
29
30 // Create learner. The network KB connects per submitted word.
31 let mut learner = LSTAR::new(vocabulary, kb, 4, None, None);
32
33 match learner.learn() {
34 Ok(automata) => {
35 println!("\n=== Learned Automaton from Network Target ===\n");
36 println!("{}", automata.build_dot_code());
37 println!(
38 "\nStates: {}\nTransitions: {}",
39 automata.get_states().len(),
40 automata.transitions.len()
41 );
42 }
43 Err(e) => {
44 eprintln!("Learning error: {}", e);
45 println!("\nTo run this example with a real connection:");
46 println!(" 1. Start a coffee server: cargo run --example coffee_server");
47 println!(" 2. Run this example again");
48 }
49 }
50
51 Ok(())
52}Sourcepub fn target_host(&self) -> &str
pub fn target_host(&self) -> &str
Gets the target hostname
Examples found in repository?
examples/network_custom_kb.rs (line 27)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("=== Network Custom KB (ATM) Example ===\n");
14
15 // Expects an independent ATM server running
16 // (see examples/custom_kb_server.rs).
17 let kb = NetworkActiveKnowledgeBase::new("127.0.0.1".to_string(), 3001, Duration::from_secs(5));
18
19 let vocabulary = vec![
20 "INSERT_CARD".to_string(),
21 "ENTER_PIN".to_string(),
22 "REQUEST_WITHDRAW".to_string(),
23 "EJECT_CARD".to_string(),
24 "TIMEOUT".to_string(),
25 ];
26
27 println!("Target Host: {}", kb.target_host());
28 println!("Target Port: {}\n", kb.target_port());
29
30 let kb: Arc<Mutex<dyn KnowledgeBaseTrait>> = Arc::new(Mutex::new(kb));
31 let mut learner = LSTAR::new(vocabulary, kb, 8, None, None);
32
33 match learner.learn() {
34 Ok(automata) => {
35 println!("\n=== Learned ATM Automaton from Network Target ===\n");
36 println!("{}", automata.build_dot_code());
37 println!(
38 "\nStates: {}\nTransitions: {}",
39 automata.get_states().len(),
40 automata.transitions.len()
41 );
42 }
43 Err(e) => {
44 eprintln!("Learning error: {}", e);
45 println!("\nTo run this example with a real connection:");
46 println!(" 1. Start ATM server: cargo run --example custom_kb_server");
47 println!(" 2. Run this example again: cargo run --example network_custom_kb");
48 }
49 }
50
51 Ok(())
52}More examples
examples/network_kb.rs (line 25)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10 println!("=== Network Active Knowledge Base Example ===\n");
11
12 // This example expects an independent coffee server running
13 // (see examples/coffee_server.rs).
14 let kb = NetworkActiveKnowledgeBase::new("127.0.0.1".to_string(), 3000, Duration::from_secs(5));
15
16 // Define input vocabulary
17 let vocabulary = vec![
18 "REFILL_WATER".to_string(),
19 "REFILL_COFFEE".to_string(),
20 "PRESS_BUTTON_A".to_string(),
21 "PRESS_BUTTON_B".to_string(),
22 "PRESS_BUTTON_C".to_string(),
23 ];
24
25 println!("Target Host: {}", kb.target_host());
26 println!("Target Port: {}\n", kb.target_port());
27
28 let kb: Arc<Mutex<dyn KnowledgeBaseTrait>> = Arc::new(Mutex::new(kb));
29
30 // Create learner. The network KB connects per submitted word.
31 let mut learner = LSTAR::new(vocabulary, kb, 4, None, None);
32
33 match learner.learn() {
34 Ok(automata) => {
35 println!("\n=== Learned Automaton from Network Target ===\n");
36 println!("{}", automata.build_dot_code());
37 println!(
38 "\nStates: {}\nTransitions: {}",
39 automata.get_states().len(),
40 automata.transitions.len()
41 );
42 }
43 Err(e) => {
44 eprintln!("Learning error: {}", e);
45 println!("\nTo run this example with a real connection:");
46 println!(" 1. Start a coffee server: cargo run --example coffee_server");
47 println!(" 2. Run this example again");
48 }
49 }
50
51 Ok(())
52}Sourcepub fn target_port(&self) -> u16
pub fn target_port(&self) -> u16
Gets the target port
Examples found in repository?
examples/network_custom_kb.rs (line 28)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("=== Network Custom KB (ATM) Example ===\n");
14
15 // Expects an independent ATM server running
16 // (see examples/custom_kb_server.rs).
17 let kb = NetworkActiveKnowledgeBase::new("127.0.0.1".to_string(), 3001, Duration::from_secs(5));
18
19 let vocabulary = vec![
20 "INSERT_CARD".to_string(),
21 "ENTER_PIN".to_string(),
22 "REQUEST_WITHDRAW".to_string(),
23 "EJECT_CARD".to_string(),
24 "TIMEOUT".to_string(),
25 ];
26
27 println!("Target Host: {}", kb.target_host());
28 println!("Target Port: {}\n", kb.target_port());
29
30 let kb: Arc<Mutex<dyn KnowledgeBaseTrait>> = Arc::new(Mutex::new(kb));
31 let mut learner = LSTAR::new(vocabulary, kb, 8, None, None);
32
33 match learner.learn() {
34 Ok(automata) => {
35 println!("\n=== Learned ATM Automaton from Network Target ===\n");
36 println!("{}", automata.build_dot_code());
37 println!(
38 "\nStates: {}\nTransitions: {}",
39 automata.get_states().len(),
40 automata.transitions.len()
41 );
42 }
43 Err(e) => {
44 eprintln!("Learning error: {}", e);
45 println!("\nTo run this example with a real connection:");
46 println!(" 1. Start ATM server: cargo run --example custom_kb_server");
47 println!(" 2. Run this example again: cargo run --example network_custom_kb");
48 }
49 }
50
51 Ok(())
52}More examples
examples/network_kb.rs (line 26)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10 println!("=== Network Active Knowledge Base Example ===\n");
11
12 // This example expects an independent coffee server running
13 // (see examples/coffee_server.rs).
14 let kb = NetworkActiveKnowledgeBase::new("127.0.0.1".to_string(), 3000, Duration::from_secs(5));
15
16 // Define input vocabulary
17 let vocabulary = vec![
18 "REFILL_WATER".to_string(),
19 "REFILL_COFFEE".to_string(),
20 "PRESS_BUTTON_A".to_string(),
21 "PRESS_BUTTON_B".to_string(),
22 "PRESS_BUTTON_C".to_string(),
23 ];
24
25 println!("Target Host: {}", kb.target_host());
26 println!("Target Port: {}\n", kb.target_port());
27
28 let kb: Arc<Mutex<dyn KnowledgeBaseTrait>> = Arc::new(Mutex::new(kb));
29
30 // Create learner. The network KB connects per submitted word.
31 let mut learner = LSTAR::new(vocabulary, kb, 4, None, None);
32
33 match learner.learn() {
34 Ok(automata) => {
35 println!("\n=== Learned Automaton from Network Target ===\n");
36 println!("{}", automata.build_dot_code());
37 println!(
38 "\nStates: {}\nTransitions: {}",
39 automata.get_states().len(),
40 automata.transitions.len()
41 );
42 }
43 Err(e) => {
44 eprintln!("Learning error: {}", e);
45 println!("\nTo run this example with a real connection:");
46 println!(" 1. Start a coffee server: cargo run --example coffee_server");
47 println!(" 2. Run this example again");
48 }
49 }
50
51 Ok(())
52}Sourcepub fn set_timeout(&mut self, timeout: Duration)
pub fn set_timeout(&mut self, timeout: Duration)
Sets the socket timeout
Source§impl NetworkActiveKnowledgeBase
impl NetworkActiveKnowledgeBase
pub fn stats(&self) -> &KnowledgeBaseStats
Trait Implementations§
Source§impl ActiveKnowledgeBase for NetworkActiveKnowledgeBase
impl ActiveKnowledgeBase for NetworkActiveKnowledgeBase
Auto Trait Implementations§
impl Freeze for NetworkActiveKnowledgeBase
impl RefUnwindSafe for NetworkActiveKnowledgeBase
impl Send for NetworkActiveKnowledgeBase
impl Sync for NetworkActiveKnowledgeBase
impl Unpin for NetworkActiveKnowledgeBase
impl UnsafeUnpin for NetworkActiveKnowledgeBase
impl UnwindSafe for NetworkActiveKnowledgeBase
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more