Trait rustfst::fst_traits::CoreFst

source ·
pub trait CoreFst<W: Semiring> {
    type TRS: Trs<W>;

Show 15 methods // Required methods fn start(&self) -> Option<StateId>; fn final_weight(&self, state: StateId) -> Result<Option<W>>; unsafe fn final_weight_unchecked(&self, state: StateId) -> Option<W>; fn num_trs(&self, s: StateId) -> Result<usize>; unsafe fn num_trs_unchecked(&self, state: StateId) -> usize; fn get_trs(&self, state_id: StateId) -> Result<Self::TRS>; unsafe fn get_trs_unchecked(&self, state: 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>; // Provided methods fn is_final(&self, state_id: StateId) -> Result<bool> { ... } unsafe fn is_final_unchecked(&self, state: 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> { ... }
}
Expand description

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

Required Associated Types§

source

type TRS: Trs<W>

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

Required Methods§

source

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));
source

fn final_weight(&self, state: 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());
source

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

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

§Safety

Unsafe behaviour if state is not present in Fst.

source

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);
source

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

Number of trs leaving a specific state in the wFST.

§Safety

Unsafe behaviour if state is not present in Fst.

source

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

Get an iterator on the transitions leaving state state.

source

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

Get an iterator on the transitions leaving state state.

§Safety

Unsafe behaviour if state is not present in Fst.

source

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.

source

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);
source

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);

Provided Methods§

source

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());
source

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

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

§Safety

Unsafe behaviour if state is not present in Fst.

source

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

Check whether a state is the start state or not.

source

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

Apply a mask to the FstProperties returned.

source

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.

Implementations on Foreign Types§

source§

impl<W: Semiring, F: CoreFst<W>> CoreFst<W> for Arc<F>

§

type TRS = <F as CoreFst<W>>::TRS

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

fn properties(&self) -> FstProperties

source§

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

source§

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

Implementors§

source§

impl<W, F1, F2, B1, B2, M1, M2, CFB, Cache> CoreFst<W> for ComposeFst<W, F1, F2, B1, B2, M1, M2, CFB, Cache>
where W: Semiring, F1: Fst<W>, F2: Fst<W>, B1: Borrow<F1> + Debug + Clone, B2: Borrow<F2> + Debug + Clone, M1: Matcher<W, F1, B1>, M2: Matcher<W, F2, B2>, CFB: ComposeFilterBuilder<W, F1, F2, B1, B2, M1, M2>, Cache: FstCache<W>,

§

type TRS = TrsVec<W>

source§

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

§

type TRS = TrsVec<W>

source§

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

§

type TRS = TrsVec<W>

source§

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

§

type TRS = TrsVec<W>

source§

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

§

type TRS = TrsVec<W>

source§

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

§

type TRS = TrsVec<W>

source§

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>,

§

type TRS = TrsVec<W>

source§

impl<W, F, B, S> CoreFst<W> for RandGenFst<W, F, B, S>
where W: Semiring<Type = f32>, F: Fst<W>, B: Borrow<F>, S: TrSelector,

§

type TRS = TrsVec<W>

source§

impl<W: Semiring> CoreFst<W> for ConstFst<W>

§

type TRS = TrsConst<W>

source§

impl<W: Semiring> CoreFst<W> for VectorFst<W>

§

type TRS = TrsVec<W>

source§

impl<W: Semiring, F: CoreFst<W>, B: Borrow<F>, M, T> CoreFst<W> for MatcherFst<W, F, B, M, T>

§

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

source§

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

§

type TRS = <F as CoreFst<W>>::TRS

source§

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

§

type TRS = TrsVec<W>

source§

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

§

type TRS = TrsVec<W>