Function rustfst::algorithms::rm_epsilon

source ·
pub fn rm_epsilon<W, F1, F2>(fst: &F1) -> Result<F2, Error>where
    W: StarSemiring,
    F1: ExpandedFst<W = W>,
    F2: MutableFst<W = W> + ExpandedFst<W = W>,
Expand description

This operation removes epsilon-transitions (when both the input and output labels are an epsilon) from a transducer. The result will be an equivalent FST that has no such epsilon transitions.

Example

use rustfst::semirings::{Semiring, IntegerWeight};
use rustfst::fst_impls::VectorFst;
use rustfst::fst_traits::MutableFst;
use rustfst::algorithms::rm_epsilon;
use rustfst::arc::Arc;
use rustfst::EPS_LABEL;

let mut fst = VectorFst::new();
let s0 = fst.add_state();
let s1 = fst.add_state();
fst.add_arc(&s0, Arc::new(32, 25, IntegerWeight::new(78), s1));
fst.add_arc(&s1, Arc::new(EPS_LABEL, EPS_LABEL, IntegerWeight::new(13), s0));
fst.set_start(&s0).unwrap();
fst.set_final(&s0, IntegerWeight::new(5));

let fst_no_epsilon : VectorFst<_> = rm_epsilon(&fst).unwrap();

let mut fst_no_epsilon_ref = VectorFst::new();
let s0 = fst_no_epsilon_ref.add_state();
let s1 = fst_no_epsilon_ref.add_state();
fst_no_epsilon_ref.add_arc(&s0, Arc::new(32, 25, IntegerWeight::new(78), s1));
fst_no_epsilon_ref.add_arc(&s1, Arc::new(32, 25, IntegerWeight::new(78 * 13), s1));
fst_no_epsilon_ref.set_start(&s0).unwrap();
fst_no_epsilon_ref.set_final(&s0, IntegerWeight::new(5));
fst_no_epsilon_ref.set_final(&s1, IntegerWeight::new(5 * 13));

assert_eq!(fst_no_epsilon, fst_no_epsilon_ref);