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§

source

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.

source

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.

source

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.

source

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.

source

fn take_input_symbols(&mut self) -> Option<Arc<SymbolTable>>

Removes the input symbol table from the Fst and retrieves it.

source

fn take_output_symbols(&mut self) -> Option<Arc<SymbolTable>>

Removes the output symbol table from the Fst and retrieves it.

Provided Methods§

source

fn final_states_iter(&self) -> FinalStatesIterator<'_, W, Self>
where Self: Sized,

Returns an Iterator on the final states along with their weight.

source

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());
source

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());

Implementations on Foreign Types§

source§

impl<W: Semiring, F: Fst<W>> Fst<W> for Arc<F>

Implementors§

source§

impl<W, F1, F2, B1, B2, M1, M2, CFB, Cache> Fst<W> for ComposeFst<W, F1, F2, B1, B2, M1, M2, CFB, Cache>
where W: Semiring, F1: Fst<W> + 'static, F2: Fst<W> + 'static, B1: Borrow<F1> + Debug + Clone + 'static, B2: Borrow<F2> + Debug + Clone + 'static, M1: Matcher<W, F1, B1> + 'static, M2: Matcher<W, F2, B2> + 'static, CFB: ComposeFilterBuilder<W, F1, F2, B1, B2, M1, M2> + 'static, Cache: FstCache<W> + 'static,

source§

impl<W, F> Fst<W> for ClosureFst<W, F>
where W: Semiring, F: Fst<W> + 'static,

source§

impl<W, F> Fst<W> for ConcatFst<W, F>
where W: Semiring, F: Fst<W> + 'static,

source§

impl<W, F> Fst<W> for UnionFst<W, F>
where W: Semiring, F: Fst<W> + 'static,

source§

impl<W, F, B> Fst<W> for ReplaceFst<W, F, B>
where W: Semiring, F: Fst<W> + 'static, B: Borrow<F> + 'static,

source§

impl<W, F, B> Fst<W> for RmEpsilonFst<W, F, B>
where W: Semiring, F: MutableFst<W> + 'static, B: Borrow<F> + 'static,

source§

impl<W, F, B, FI> Fst<W> for FactorWeightFst<W, F, B, FI>
where W: WeightQuantize, F: Fst<W> + 'static, B: Borrow<F> + 'static, FI: FactorIterator<W> + 'static,

source§

impl<W, F, B, M, T> Fst<W> for MatcherFst<W, F, B, M, T>
where W: Semiring, F: Fst<W>, B: Borrow<F> + Debug, M: Debug, T: Debug,

source§

impl<W, F, B, S> Fst<W> for RandGenFst<W, F, B, S>
where W: Semiring<Type = f32>, F: Fst<W> + 'static, B: Borrow<F> + 'static, S: TrSelector + 'static,

source§

impl<W, F, T: Debug> Fst<W> for FstAddOn<F, T>
where W: Semiring, F: Fst<W>,

source§

impl<W, Op, Cache> Fst<W> for LazyFst2<W, Op, Cache>
where W: Semiring, Op: FstOp2<W> + 'static, Cache: FstCache<W> + 'static,

source§

impl<W, Op, Cache> Fst<W> for LazyFst<W, Op, Cache>
where W: Semiring, Op: FstOp<W> + 'static, Cache: FstCache<W> + 'static,

source§

impl<W: Semiring> Fst<W> for ConstFst<W>

source§

impl<W: Semiring> Fst<W> for VectorFst<W>