[][src]Trait rustfst::fst_traits::CoreFst

pub trait CoreFst<W: Semiring> {
    type TRS: Trs<W>;
    fn start(&self) -> Option<StateId>;
fn final_weight(&self, state_id: StateId) -> Result<Option<W>>;
unsafe fn final_weight_unchecked(&self, state_id: StateId) -> Option<W>;
fn num_trs(&self, s: StateId) -> Result<usize>;
unsafe fn num_trs_unchecked(&self, s: StateId) -> usize;
fn get_trs(&self, state_id: StateId) -> Result<Self::TRS>;
unsafe fn get_trs_unchecked(&self, state_id: StateId) -> Self::TRS;
fn properties(&self) -> FstProperties;
fn num_input_epsilons(&self, state: StateId) -> Result<usize>;
fn num_output_epsilons(&self, state: StateId) -> Result<usize>; fn is_final(&self, state_id: StateId) -> Result<bool> { ... }
unsafe fn is_final_unchecked(&self, state_id: StateId) -> bool { ... }
fn is_start(&self, state_id: StateId) -> bool { ... }
fn properties_with_mask(&self, mask: FstProperties) -> FstProperties { ... }
fn properties_check(
        &self,
        props_known: FstProperties
    ) -> Result<FstProperties> { ... } }

Trait defining necessary methods for a wFST to access start states and final states.

Associated Types

type TRS: Trs<W>

Weight use in the wFST. This type must implement the Semiring trait.

Loading content...

Required methods

fn start(&self) -> Option<StateId>

Returns the ID of the start state of the wFST if it exists else none.

Example

// 1 - Create an FST
let mut fst = VectorFst::<BooleanWeight>::new();
let s = fst.add_state();
fst.set_start(s);

// 2 - Access the start state
let start_state = fst.start();
assert_eq!(start_state, Some(s));

fn final_weight(&self, state_id: StateId) -> Result<Option<W>>

Retrieves the final weight of a state (if the state is a final one).

Example

// 1 - Create an FST
let mut fst = VectorFst::<BooleanWeight>::new();
let s1 = fst.add_state();
let s2 = fst.add_state();
fst.set_final(s2, BooleanWeight::one());

// 2 - Access the final weight of each state
assert_eq!(fst.final_weight(s1).unwrap(), None);
assert_eq!(fst.final_weight(s2).unwrap(), Some(BooleanWeight::one()));
assert!(fst.final_weight(s2 + 1).is_err());

unsafe fn final_weight_unchecked(&self, state_id: StateId) -> Option<W>

fn num_trs(&self, s: StateId) -> Result<usize>

Number of trs leaving a specific state in the wFST.

Example

let mut fst = VectorFst::<BooleanWeight>::new();
let s1 = fst.add_state();
let s2 = fst.add_state();

assert_eq!(fst.num_trs(s1).unwrap(), 0);
fst.add_tr(s1, Tr::new(3, 5, BooleanWeight::new(true), s2));
assert_eq!(fst.num_trs(s1).unwrap(), 1);

unsafe fn num_trs_unchecked(&self, s: StateId) -> usize

fn get_trs(&self, state_id: StateId) -> Result<Self::TRS>

unsafe fn get_trs_unchecked(&self, state_id: StateId) -> Self::TRS

fn properties(&self) -> FstProperties

Retrieve the FstProperties stored in the Fst. As a result, all the properties returned are verified by the Fst but some other properties might be true as well despite the flag not being set.

fn num_input_epsilons(&self, state: StateId) -> Result<usize>

Returns the number of trs with epsilon input labels leaving a state.

Example :

let mut fst = VectorFst::<IntegerWeight>::new();
let s0 = fst.add_state();
let s1 = fst.add_state();

fst.add_tr(s0, Tr::new(EPS_LABEL, 18, IntegerWeight::one(), s1));
fst.add_tr(s0, Tr::new(76, EPS_LABEL, IntegerWeight::one(), s1));
fst.add_tr(s0, Tr::new(EPS_LABEL, 18, IntegerWeight::one(), s1));
fst.add_tr(s0, Tr::new(45, 18, IntegerWeight::one(), s0));
fst.add_tr(s1, Tr::new(76, 18, IntegerWeight::one(), s1));

assert_eq!(fst.num_input_epsilons(s0).unwrap(), 2);
assert_eq!(fst.num_input_epsilons(s1).unwrap(), 0);

fn num_output_epsilons(&self, state: StateId) -> Result<usize>

Returns the number of trs with epsilon output labels leaving a state.

Example :

let mut fst = VectorFst::<IntegerWeight>::new();
let s0 = fst.add_state();
let s1 = fst.add_state();

fst.add_tr(s0, Tr::new(EPS_LABEL, 18, IntegerWeight::one(), s1));
fst.add_tr(s0, Tr::new(76, EPS_LABEL, IntegerWeight::one(), s1));
fst.add_tr(s0, Tr::new(EPS_LABEL, 18, IntegerWeight::one(), s1));
fst.add_tr(s0, Tr::new(45, 18, IntegerWeight::one(), s0));
fst.add_tr(s1, Tr::new(76, 18, IntegerWeight::one(), s1));

assert_eq!(fst.num_output_epsilons(s0).unwrap(), 1);
assert_eq!(fst.num_output_epsilons(s1).unwrap(), 0);
Loading content...

Provided methods

fn is_final(&self, state_id: StateId) -> Result<bool>

Returns whether or not the state with identifier passed as parameters is a final state.

Example

// 1 - Create an FST
let mut fst = VectorFst::<BooleanWeight>::new();
let s1 = fst.add_state();
let s2 = fst.add_state();
fst.set_final(s2, BooleanWeight::one());

// 2 - Test if a state is final
assert_eq!(fst.is_final(s1).unwrap(), false);
assert_eq!(fst.is_final(s2).unwrap(), true);
assert!(fst.is_final(s2 + 1).is_err());

unsafe fn is_final_unchecked(&self, state_id: StateId) -> bool

fn is_start(&self, state_id: StateId) -> bool

Check whether a state is the start state or not.

fn properties_with_mask(&self, mask: FstProperties) -> FstProperties

Apply a mask to the FstProperties returned.

fn properties_check(&self, props_known: FstProperties) -> Result<FstProperties>

Retrieve the FstProperties in the Fst and check that all the properties in props_known are known (not the same as true). If not an error is returned.

A property is known if we known for sure if it is true of false.

Loading content...

Implementations on Foreign Types

impl<W: Semiring, F: CoreFst<W>> CoreFst<W> for Arc<F>[src]

type TRS = F::TRS

Loading content...

Implementors

impl<W, CFB, Cache> CoreFst<W> for ComposeFst<W, CFB, Cache> where
    W: Semiring,
    CFB: ComposeFilterBuilder<W>,
    Cache: FstCache<W>, 
[src]

type TRS = TrsVec<W>

impl<W, F> CoreFst<W> for ClosureFst<W, F> where
    W: Semiring,
    F: Fst<W>, 
[src]

type TRS = TrsVec<W>

impl<W, F> CoreFst<W> for ConcatFst<W, F> where
    W: Semiring,
    F: Fst<W>, 
[src]

type TRS = TrsVec<W>

impl<W, F> CoreFst<W> for UnionFst<W, F> where
    W: Semiring,
    F: Fst<W>, 
[src]

type TRS = TrsVec<W>

impl<W, F, B> CoreFst<W> for ReplaceFst<W, F, B> where
    W: Semiring,
    F: Fst<W>,
    B: Borrow<F>, 
[src]

type TRS = TrsVec<W>

impl<W, F, B> CoreFst<W> for RmEpsilonFst<W, F, B> where
    W: Semiring,
    F: MutableFst<W>,
    B: Borrow<F>, 
[src]

type TRS = TrsVec<W>

impl<W, F, B, FI> CoreFst<W> for FactorWeightFst<W, F, B, FI> where
    W: WeightQuantize,
    F: Fst<W>,
    B: Borrow<F>,
    FI: FactorIterator<W>, 
[src]

type TRS = TrsVec<W>

impl<W: Semiring> CoreFst<W> for ConstFst<W>[src]

type TRS = TrsConst<W>

impl<W: Semiring> CoreFst<W> for VectorFst<W>[src]

type TRS = TrsVec<W>

impl<W: Semiring, F: CoreFst<W>, M, T> CoreFst<W> for MatcherFst<W, F, M, T>[src]

type TRS = <FstAddOn<F, T> as CoreFst<W>>::TRS

impl<W: Semiring, F: CoreFst<W>, T> CoreFst<W> for FstAddOn<F, T>[src]

type TRS = F::TRS

impl<W: Semiring, Op: FstOp2<W>, Cache: FstCache<W>> CoreFst<W> for LazyFst2<W, Op, Cache>[src]

type TRS = TrsVec<W>

impl<W: Semiring, Op: FstOp<W>, Cache: FstCache<W>> CoreFst<W> for LazyFst<W, Op, Cache>[src]

type TRS = TrsVec<W>

Loading content...