Trait rustfst::fst_traits::Fst
source · pub trait Fst<W: Semiring>: CoreFst<W> + for<'b> StateIterator<'b> + Debug + for<'c> FstIterator<'c, W> {
// Required methods
fn input_symbols(&self) -> Option<&Arc<SymbolTable>>;
fn output_symbols(&self) -> Option<&Arc<SymbolTable>>;
fn set_input_symbols(&mut self, symt: Arc<SymbolTable>);
fn set_output_symbols(&mut self, symt: Arc<SymbolTable>);
fn take_input_symbols(&mut self) -> Option<Arc<SymbolTable>>;
fn take_output_symbols(&mut self) -> Option<Arc<SymbolTable>>;
// Provided methods
fn final_states_iter(&self) -> FinalStatesIterator<'_, W, Self>
where Self: Sized { ... }
fn paths_iter(&self) -> PathsIterator<'_, W, Self> ⓘ
where Self: Sized { ... }
fn string_paths_iter(&self) -> Result<StringPathsIterator<'_, W, Self>>
where Self: Sized { ... }
}
Expand description
Trait defining the minimum interface necessary for a wFST.
Required Methods§
sourcefn input_symbols(&self) -> Option<&Arc<SymbolTable>>
fn input_symbols(&self) -> Option<&Arc<SymbolTable>>
Retrieves the input SymbolTable
associated to the Fst.
If no SymbolTable has been previously attached then None
is returned.
sourcefn output_symbols(&self) -> Option<&Arc<SymbolTable>>
fn output_symbols(&self) -> Option<&Arc<SymbolTable>>
Retrieves the output SymbolTable
associated to the Fst.
If no SymbolTable has been previously attached then None
is returned.
sourcefn set_input_symbols(&mut self, symt: Arc<SymbolTable>)
fn set_input_symbols(&mut self, symt: Arc<SymbolTable>)
Attaches an output SymbolTable
to the Fst.
The SymbolTable
is not duplicated with the use of Arc.
sourcefn set_output_symbols(&mut self, symt: Arc<SymbolTable>)
fn set_output_symbols(&mut self, symt: Arc<SymbolTable>)
Attaches an output SymbolTable
to the Fst.
The SymbolTable
is not duplicated with the use of Arc.
sourcefn take_input_symbols(&mut self) -> Option<Arc<SymbolTable>>
fn take_input_symbols(&mut self) -> Option<Arc<SymbolTable>>
Removes the input symbol table from the Fst and retrieves it.
sourcefn take_output_symbols(&mut self) -> Option<Arc<SymbolTable>>
fn take_output_symbols(&mut self) -> Option<Arc<SymbolTable>>
Removes the output symbol table from the Fst and retrieves it.
Provided Methods§
sourcefn final_states_iter(&self) -> FinalStatesIterator<'_, W, Self>where
Self: Sized,
fn final_states_iter(&self) -> FinalStatesIterator<'_, W, Self>where
Self: Sized,
Returns an Iterator on the final states along with their weight.
sourcefn paths_iter(&self) -> PathsIterator<'_, W, Self> ⓘwhere
Self: Sized,
fn paths_iter(&self) -> PathsIterator<'_, W, Self> ⓘwhere
Self: Sized,
Returns an Iterator on the paths accepted by the Fst.
§Example :
let mut fst : VectorFst<_> = transducer(&[1, 2, 3], &[4, 5], TropicalWeight::one());
let paths : Vec<_> = fst.paths_iter().collect();
assert_eq!(paths.len(), 1);
assert_eq!(paths[0].ilabels.as_slice(), &[1, 2, 3]);
assert_eq!(paths[0].olabels.as_slice(), &[4, 5]);
assert_eq!(&paths[0].weight, &TropicalWeight::one());
sourcefn string_paths_iter(&self) -> Result<StringPathsIterator<'_, W, Self>>where
Self: Sized,
fn string_paths_iter(&self) -> Result<StringPathsIterator<'_, W, Self>>where
Self: Sized,
Returns an Iterator on the paths accepted by the Fst. Plus, handles the SymbolTable allowing to retrieve the strings instead of only the sequence of labels.
§Example :
let mut fst : VectorFst<_> = transducer(&[1, 2, 3], &[4, 5], TropicalWeight::one());
let symt = symt!["a", "b", "c", "d", "e"];
let symt = Arc::new(symt);
fst.set_input_symbols(Arc::clone(&symt));
fst.set_output_symbols(Arc::clone(&symt));
let paths : Vec<_> = fst.string_paths_iter().unwrap().collect();
assert_eq!(paths.len(), 1);
assert_eq!(paths[0].ilabels(), &[1, 2, 3]);
assert_eq!(paths[0].olabels(), &[4, 5]);
assert_eq!(paths[0].weight(), &TropicalWeight::one());
assert_eq!(paths[0].istring().unwrap(), "a b c".to_string());
assert_eq!(paths[0].ostring().unwrap(), "d e".to_string());