Skip to main content

NetworkActiveKnowledgeBase

Struct NetworkActiveKnowledgeBase 

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

An active knowledge base that communicates with a remote target via network

Implementations§

Source§

impl NetworkActiveKnowledgeBase

Source

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 target
  • target_port - Port number of the target service
  • timeout - 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
Hide additional 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}
Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

pub fn timeout(&self) -> Duration

Gets the socket timeout

Source

pub fn set_timeout(&mut self, timeout: Duration)

Sets the socket timeout

Source§

impl NetworkActiveKnowledgeBase

Trait Implementations§

Source§

impl ActiveKnowledgeBase for NetworkActiveKnowledgeBase

Source§

fn start_target(&mut self) -> Result<(), String>

Starts the target system for querying
Source§

fn stop_target(&mut self) -> Result<(), String>

Stops the target system after querying
Source§

fn submit_word(&mut self, word: &Word) -> Result<Word, String>

Submits a word to the target and returns the output
Source§

fn is_target_running(&self) -> bool

Gets the current state of the target (started or stopped)
Source§

impl KnowledgeBaseTrait for NetworkActiveKnowledgeBase

Source§

fn resolve_query(&mut self, query: &mut OutputQuery) -> Result<(), String>

Source§

fn add_word( &mut self, input_word: &Word, output_word: &Word, ) -> Result<(), String>

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
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.