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§
Required Methods§
sourcefn start(&self) -> Option<StateId>
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));
sourcefn final_weight(&self, state: StateId) -> Result<Option<W>>
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());
sourceunsafe fn final_weight_unchecked(&self, state: StateId) -> Option<W>
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.
sourcefn num_trs(&self, s: StateId) -> Result<usize>
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);
sourceunsafe fn num_trs_unchecked(&self, state: StateId) -> usize
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.
sourcefn get_trs(&self, state_id: StateId) -> Result<Self::TRS>
fn get_trs(&self, state_id: StateId) -> Result<Self::TRS>
Get an iterator on the transitions leaving state state
.
sourceunsafe fn get_trs_unchecked(&self, state: StateId) -> Self::TRS
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.
sourcefn properties(&self) -> FstProperties
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.
sourcefn num_input_epsilons(&self, state: StateId) -> Result<usize>
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);
sourcefn num_output_epsilons(&self, state: StateId) -> Result<usize>
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§
sourcefn is_final(&self, state_id: StateId) -> Result<bool>
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());
sourceunsafe fn is_final_unchecked(&self, state: StateId) -> bool
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.
sourcefn properties_with_mask(&self, mask: FstProperties) -> FstProperties
fn properties_with_mask(&self, mask: FstProperties) -> FstProperties
Apply a mask to the FstProperties
returned.
sourcefn properties_check(&self, props_known: FstProperties) -> Result<FstProperties>
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.