[−][src]Function rustfst::utils::transducer
pub fn transducer<W: Semiring, F: MutableFst<W>>(
labels_input: &[Label],
labels_output: &[Label],
weight: W
) -> F
Turns a list of input labels and output labels into a linear FST.
The only accepted path in the FST has for input labels_input
and for output labels_output
.
Example
let labels_input = vec![32, 43, 21]; let labels_output = vec![53, 18, 89]; let fst : VectorFst<ProbabilityWeight> = transducer(&labels_input, &labels_output, ProbabilityWeight::one()); assert_eq!(fst.num_states(), 4); // The transducer function produces the same FST as the following code let mut fst_ref = VectorFst::new(); let s1 = fst_ref.add_state(); let s2 = fst_ref.add_state(); let s3 = fst_ref.add_state(); let s4 = fst_ref.add_state(); fst_ref.set_start(s1).unwrap(); fst_ref.set_final(s4, ProbabilityWeight::one()).unwrap(); fst_ref.add_tr(s1, Tr::new(labels_input[0], labels_output[0], ProbabilityWeight::one(), s2)).unwrap(); fst_ref.add_tr(s2, Tr::new(labels_input[1], labels_output[1], ProbabilityWeight::one(), s3)).unwrap(); fst_ref.add_tr(s3, Tr::new(labels_input[2], labels_output[2], ProbabilityWeight::one(), s4)).unwrap(); assert_eq!(fst, fst_ref);