Skip to main content

concat

Function concat 

Source
pub fn concat<W, F1, F2, M>(fst1: &F1, fst2: &F2) -> Result<M>
where W: Semiring, F1: Fst<W>, F2: Fst<W>, M: MutableFst<W> + Default,
Expand description

Concatenates two FSTs to create an FST accepting $T_1$ followed by $T_2$.

Creates a new FST that accepts any string of the form $xy$ where $x$ is accepted by the first FST and $y$ is accepted by the second FST: $L(T_1 \cdot T_2) = \{xy : x \in L(T_1), y \in L(T_2)\}$

Weights combine through semiring multiplication: $(T_1 \cdot T_2)(xy) = T_1(x) \otimes T_2(y)$.

§Arguments

  • fst1 - The first FST (prefix)
  • fst2 - The second FST (suffix)

§Type Parameters

§Returns

A new FST accepting the concatenation of the two input languages.

§Errors

Returns Error::Algorithm if either input FST is invalid.

§Examples

use arcweight::prelude::*;

// FST 1: accepts "a"
let mut fst1 = VectorFst::<TropicalWeight>::new();
let s0 = fst1.add_state();
let s1 = fst1.add_state();
fst1.set_start(s0);
fst1.set_final(s1, TropicalWeight::new(0.5));
fst1.add_arc(s0, Arc::new('a' as u32, 'a' as u32, TropicalWeight::one(), s1));

// FST 2: accepts "b"
let mut fst2 = VectorFst::<TropicalWeight>::new();
let s0 = fst2.add_state();
let s1 = fst2.add_state();
fst2.set_start(s0);
fst2.set_final(s1, TropicalWeight::new(0.3));
fst2.add_arc(s0, Arc::new('b' as u32, 'b' as u32, TropicalWeight::one(), s1));

// Concatenation accepts "ab"
let result: VectorFst<TropicalWeight> = concat(&fst1, &fst2)?;

assert_eq!(result.num_states(), fst1.num_states() + fst2.num_states());

§References

  • John E. Hopcroft and Jeffrey D. Ullman. 1979. Introduction to Automata Theory, Languages, and Computation. Addison-Wesley, Reading, MA.