Skip to main content

OutputQuery

Struct OutputQuery 

Source
pub struct OutputQuery {
    pub input_word: Word,
    pub output_word: Option<Word>,
    pub queried: bool,
}
Expand description

Represents a query to be executed against the system under learning (SUL)

Fields§

§input_word: Word§output_word: Option<Word>§queried: bool

Implementations§

Source§

impl OutputQuery

Source

pub fn new(input_word: Word) -> Self

Create a new output query

Source

pub fn is_queried(&self) -> bool

Check if the query has been executed

Source

pub fn set_result(&mut self, output_word: Word)

Set the result of the query

Examples found in repository?
examples/memory_kb.rs (line 81)
75    fn resolve_query(&mut self, query: &mut OutputQuery) -> Result<(), String> {
76        match self.base.resolve_query(query) {
77            Ok(_) => Ok(()),
78            Err(_) => {
79                let output = self.submit_word_to_target(&query.input_word)?;
80                self.base.add_word(&query.input_word, &output)?;
81                query.set_result(output);
82                Ok(())
83            }
84        }
85    }
More examples
Hide additional examples
examples/all_eqtests_custom_kb.rs (line 224)
208    fn resolve_query(&mut self, query: &mut OutputQuery) -> Result<(), String> {
209        self.stats.increment_nb_query();
210        self.stats.add_nb_letter(query.input_word.len());
211        self.stats.increment_nb_submitted_query();
212        self.stats.add_nb_submitted_letter(query.input_word.len());
213
214        self.state = ATMState::Idle;
215        let mut outputs = Vec::new();
216
217        for input_letter in query.input_word.letters() {
218            let command = input_letter.symbols();
219            let (next_state, response) = self.process_input(command.as_str(), self.state);
220            self.state = next_state;
221            outputs.push(Letter::new(response));
222        }
223
224        query.set_result(Word::from_letters(outputs));
225        Ok(())
226    }
examples/vending_machine.rs (line 94)
75    fn resolve_query(&mut self, query: &mut OutputQuery) -> Result<(), String> {
76        self.stats.increment_nb_query();
77        self.stats.add_nb_letter(query.input_word.len());
78        self.stats.increment_nb_submitted_query();
79        self.stats.add_nb_submitted_letter(query.input_word.len());
80
81        // Reset to initial state for each query
82        self.state = VendingState::Idle;
83
84        let mut outputs = Vec::new();
85        for input_letter in query.input_word.letters() {
86            let command_string = input_letter.symbols();
87            let command = command_string.as_str();
88
89            let (next, resp) = self.process_input(command, self.state);
90            self.state = next;
91            outputs.push(Letter::new(resp));
92        }
93
94        query.set_result(Word::from_letters(outputs));
95        Ok(())
96    }
examples/custom_kb.rs (line 115)
94    fn resolve_query(&mut self, query: &mut OutputQuery) -> Result<(), String> {
95        self.stats.increment_nb_query();
96        self.stats.add_nb_letter(query.input_word.len());
97        self.stats.increment_nb_submitted_query();
98        self.stats.add_nb_submitted_letter(query.input_word.len());
99        // Reset to initial state for each query
100        self.state = ATMState::Idle;
101
102        // let mut state = self.state.lock().unwrap();
103        let mut outputs = Vec::new();
104
105        for input_letter in query.input_word.letters() {
106            // Extract command from letter name (format: "Letter('x')")
107            let symbol = input_letter.symbols();
108            let command = symbol.as_str();
109
110            let (next_state, response) = self.process_input(command, self.state);
111            self.state = next_state;
112            outputs.push(Letter::new(response));
113        }
114
115        query.set_result(Word::from_letters(outputs));
116        Ok(())
117    }
examples/benchmark.rs (line 111)
89    fn resolve_query(&mut self, query: &mut OutputQuery) -> Result<(), String> {
90        self.stats.increment_nb_query();
91        self.stats.add_nb_letter(query.input_word.len());
92        self.stats.increment_nb_submitted_query();
93        self.stats.add_nb_submitted_letter(query.input_word.len());
94
95        self.current_state = "s0".to_string();
96        let mut output_letters = Vec::new();
97
98        for input_letter in query.input_word.letters() {
99            let input = input_letter.symbols();
100            let key = (self.current_state.clone(), input);
101            let (output, next_state) = self
102                .transitions
103                .get(&key)
104                .cloned()
105                .ok_or_else(|| format!("No transition for ({}, {})", key.0, key.1))?;
106
107            output_letters.push(Letter::new(output));
108            self.current_state = next_state;
109        }
110
111        query.set_result(Word::from_letters(output_letters));
112        Ok(())
113    }
examples/random_walk_eq.rs (line 120)
98    fn resolve_query(&mut self, query: &mut OutputQuery) -> Result<(), String> {
99        self.stats.increment_nb_query();
100        self.stats.add_nb_letter(query.input_word.len());
101        self.stats.increment_nb_submitted_query();
102        self.stats.add_nb_submitted_letter(query.input_word.len());
103
104        self.current_state = "s0".to_string();
105        let mut output_letters = Vec::new();
106
107        for input_letter in query.input_word.letters() {
108            let input = input_letter.symbols();
109            let key = (self.current_state.clone(), input);
110            let (output, next_state) = self
111                .transitions
112                .get(&key)
113                .cloned()
114                .ok_or_else(|| format!("No transition for ({}, {})", key.0, key.1))?;
115
116            output_letters.push(Letter::new(output));
117            self.current_state = next_state;
118        }
119
120        query.set_result(Word::from_letters(output_letters));
121        Ok(())
122    }
Source

pub fn output_word(&self) -> Option<&Word>

Get the output word (if query has been executed)

Trait Implementations§

Source§

impl Clone for OutputQuery

Source§

fn clone(&self) -> OutputQuery

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OutputQuery

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.