Function rustfst::algorithms::concat

source ·
pub fn concat<W, F1, F2, F3>(fst_1: &F1, fst_2: &F2) -> Result<F3, Error>where
    W: Semiring,
    F1: ExpandedFst<W = W>,
    F2: ExpandedFst<W = W>,
    F3: MutableFst<W = W>,
Expand description

Performs the concatenation of two wFSTs. If A transduces string x to y with weight a and B transduces string w to v with weight b, then their concatenation transduces string xw to yv with weight a ⊗ b.

Example

use rustfst::utils::transducer;
use rustfst::semirings::{Semiring, IntegerWeight};
use rustfst::fst_impls::VectorFst;
use rustfst::fst_traits::PathsIterator;
use rustfst::path::Path;
use rustfst::algorithms::concat;
use std::collections::HashSet;

let fst_a : VectorFst<IntegerWeight> = transducer(vec![2].into_iter(), vec![3].into_iter()).unwrap();
let fst_b : VectorFst<IntegerWeight> = transducer(vec![6].into_iter(), vec![5].into_iter()).unwrap();

let fst_res : VectorFst<IntegerWeight> = concat(&fst_a, &fst_b).unwrap();
let paths : HashSet<_> = fst_res.paths_iter().collect();

let mut paths_ref = HashSet::new();
paths_ref.insert(Path::new(vec![2, 6], vec![3, 5], IntegerWeight::one()));

assert_eq!(paths, paths_ref);