pub struct VectorFst<W: Semiring> { /* private fields */ }
Expand description
Simple concrete, mutable FST whose states and trs are stored in standard vectors.
All states are stored in a vector of states. In each state, there is a vector of trs containing the outgoing transitions.
Implementations§
source§impl<W: Semiring> VectorFst<W>
impl<W: Semiring> VectorFst<W>
pub fn update_properties_after_add_tr(&mut self, state: StateId)
pub fn static_properties() -> u64
source§impl<W: SerializableSemiring> VectorFst<W>
impl<W: SerializableSemiring> VectorFst<W>
sourcepub fn read_from_const<P: AsRef<Path>>(path_bin_fst: P) -> Result<Self>
pub fn read_from_const<P: AsRef<Path>>(path_bin_fst: P) -> Result<Self>
Load a VectorFst directly from a ConstFst file.
Trait Implementations§
source§impl<W: 'static + Semiring> AllocableFst<W> for VectorFst<W>
impl<W: 'static + Semiring> AllocableFst<W> for VectorFst<W>
source§fn reserve_trs(&mut self, source: StateId, additional: usize) -> Result<()>
fn reserve_trs(&mut self, source: StateId, additional: usize) -> Result<()>
Reserve capacity for at least additional more trs leaving the state.
The FST may reserve more space to avoid frequent allocation.
After calling
reserve_trs
, the capacity will be greater or equal to num_trs
+ additionnal
This method has no effects if the capacity is already sufficientsource§unsafe fn reserve_trs_unchecked(&mut self, source: StateId, additional: usize)
unsafe fn reserve_trs_unchecked(&mut self, source: StateId, additional: usize)
Safety Read more
source§fn reserve_states(&mut self, additional: usize)
fn reserve_states(&mut self, additional: usize)
Reserve capacity for at least additional states.
The FST may reserve more space to avoid frequent allocation.
After calling
reserve_states
, the capacity will be greater or equal to num_states
+ additionnal
This method has no effects if the capacity is already sufficientsource§fn shrink_to_fit(&mut self)
fn shrink_to_fit(&mut self)
Shrinks the capacity of the states and their leaving trs as much as possible.
It will drop down as close as possible to the number of states and leaving trs.
source§fn shrink_to_fit_states(&mut self)
fn shrink_to_fit_states(&mut self)
Shrinks the capacity of the states.
It will drop down as close as possible to the number of states.
source§fn shrink_to_fit_trs(&mut self, source: StateId) -> Result<()>
fn shrink_to_fit_trs(&mut self, source: StateId) -> Result<()>
Shrinks the capacity of the leaving trs for the given state as much as possible.
It will drop down as close as possible to theleaving trs.
source§unsafe fn shrink_to_fit_trs_unchecked(&mut self, source: StateId)
unsafe fn shrink_to_fit_trs_unchecked(&mut self, source: StateId)
Shrinks the capacity of the leaving trs for the given state as much as possible.
It will drop down as close as possible to theleaving trs. Read more
source§fn states_capacity(&self) -> usize
fn states_capacity(&self) -> usize
Returns the number of states the FST can hold without reallocating.
source§impl<W: Semiring> CoreFst<W> for VectorFst<W>
impl<W: Semiring> CoreFst<W> for VectorFst<W>
source§fn start(&self) -> Option<StateId>
fn start(&self) -> Option<StateId>
Returns the ID of the start state of the wFST if it exists else none. Read more
source§fn final_weight(&self, state_id: StateId) -> Result<Option<W>>
fn final_weight(&self, state_id: StateId) -> Result<Option<W>>
Retrieves the final weight of a state (if the state is a final one). Read more
source§unsafe fn final_weight_unchecked(&self, state_id: StateId) -> Option<W>
unsafe fn final_weight_unchecked(&self, state_id: StateId) -> Option<W>
Retrieves the final weight of a state (if the state is a final one). Read more
source§fn 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. Read more
source§unsafe fn num_trs_unchecked(&self, s: StateId) -> usize
unsafe fn num_trs_unchecked(&self, s: StateId) -> usize
Number of trs leaving a specific state in the wFST. Read more
source§fn 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
.source§unsafe fn get_trs_unchecked(&self, state_id: StateId) -> Self::TRS
unsafe fn get_trs_unchecked(&self, state_id: StateId) -> Self::TRS
Get an iterator on the transitions leaving state
state
. Read moresource§fn 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.source§fn 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. Read more
source§fn 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. Read more
source§fn 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. Read more
source§unsafe 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. Read more
source§fn is_start(&self, state_id: StateId) -> bool
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
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>
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. Read moresource§impl<W: 'static + SerializableSemiring> Display for VectorFst<W>
impl<W: 'static + SerializableSemiring> Display for VectorFst<W>
source§impl<W: 'static + Semiring> ExpandedFst<W> for VectorFst<W>
impl<W: 'static + Semiring> ExpandedFst<W> for VectorFst<W>
source§fn num_states(&self) -> usize
fn num_states(&self) -> usize
Returns the number of states that contains the FST. They are all counted even if some states
are not on a successful path (doesn’t perform triming). Read more
fn states_range(&self) -> Range<StateId>
fn approx_equal<F2: ExpandedFst<W>>(&self, fst2: &F2, delta: f32) -> bool
source§impl<W: Semiring> Fst<W> for VectorFst<W>
impl<W: Semiring> Fst<W> for VectorFst<W>
source§fn input_symbols(&self) -> Option<&Arc<SymbolTable>>
fn input_symbols(&self) -> Option<&Arc<SymbolTable>>
Retrieves the input
SymbolTable
associated to the Fst.
If no SymbolTable has been previously attached then None
is returned.source§fn output_symbols(&self) -> Option<&Arc<SymbolTable>>
fn output_symbols(&self) -> Option<&Arc<SymbolTable>>
Retrieves the output
SymbolTable
associated to the Fst.
If no SymbolTable has been previously attached then None
is returned.source§fn set_input_symbols(&mut self, symt: Arc<SymbolTable>)
fn set_input_symbols(&mut self, symt: Arc<SymbolTable>)
Attaches an output
SymbolTable
to the Fst.
The SymbolTable
is not duplicated with the use of Arc.source§fn set_output_symbols(&mut self, symt: Arc<SymbolTable>)
fn set_output_symbols(&mut self, symt: Arc<SymbolTable>)
Attaches an output
SymbolTable
to the Fst.
The SymbolTable
is not duplicated with the use of Arc.source§fn take_input_symbols(&mut self) -> Option<Arc<SymbolTable>>
fn take_input_symbols(&mut self) -> Option<Arc<SymbolTable>>
Removes the input symbol table from the Fst and retrieves it.
source§fn take_output_symbols(&mut self) -> Option<Arc<SymbolTable>>
fn take_output_symbols(&mut self) -> Option<Arc<SymbolTable>>
Removes the output symbol table from the Fst and retrieves it.
source§fn final_states_iter(&self) -> FinalStatesIterator<'_, W, Self>where
Self: Sized,
fn final_states_iter(&self) -> FinalStatesIterator<'_, W, Self>where
Self: Sized,
Returns an Iterator on the final states along with their weight.
source§fn paths_iter(&self) -> PathsIterator<'_, W, Self> ⓘwhere
Self: Sized,
fn paths_iter(&self) -> PathsIterator<'_, W, Self> ⓘwhere
Self: Sized,
Returns an Iterator on the paths accepted by the Fst. Read more
source§fn string_paths_iter(&self) -> Result<StringPathsIterator<'_, W, Self>>where
Self: Sized,
fn string_paths_iter(&self) -> Result<StringPathsIterator<'_, W, Self>>where
Self: Sized,
Returns an Iterator on the paths accepted by the Fst. Plus, handles the SymbolTable
allowing to retrieve the strings instead of only the sequence of labels. Read more
source§impl<W: Semiring> FstIntoIterator<W> for VectorFst<W>
impl<W: Semiring> FstIntoIterator<W> for VectorFst<W>
source§impl<'a, W: Semiring + 'static> FstIterator<'a, W> for VectorFst<W>
impl<'a, W: Semiring + 'static> FstIterator<'a, W> for VectorFst<W>
source§impl<W: Semiring> MutableFst<W> for VectorFst<W>
impl<W: Semiring> MutableFst<W> for VectorFst<W>
source§fn sort_trs_unchecked<F: Fn(&Tr<W>, &Tr<W>) -> Ordering>(
&mut self,
state: StateId,
f: F
)
fn sort_trs_unchecked<F: Fn(&Tr<W>, &Tr<W>) -> Ordering>( &mut self, state: StateId, f: F )
DOESN’T MODIFY THE PROPERTIES
source§unsafe fn unique_trs_unchecked(&mut self, state: StateId)
unsafe fn unique_trs_unchecked(&mut self, state: StateId)
DOESN’T MODIFY THE PROPERTIES
source§unsafe fn sum_trs_unchecked(&mut self, state: StateId)
unsafe fn sum_trs_unchecked(&mut self, state: StateId)
DOESN’T MODIFY THE PROPERTIES
source§fn set_start(&mut self, state_id: StateId) -> Result<()>
fn set_start(&mut self, state_id: StateId) -> Result<()>
The state with identifier
state_id
is now the start state.
Note that only one start state is allowed in this implementation. Calling this function twice
will mean losing the first start state.
If the state_id
doesn’t exist an error is raised. Read moresource§unsafe fn set_start_unchecked(&mut self, state_id: StateId)
unsafe fn set_start_unchecked(&mut self, state_id: StateId)
The state with identifier
state_id
is now the start state. Read moresource§fn set_final<S: Into<W>>(
&mut self,
state_id: StateId,
final_weight: S
) -> Result<()>
fn set_final<S: Into<W>>( &mut self, state_id: StateId, final_weight: S ) -> Result<()>
The state with identifier
state_id
is now a final state with a weight final_weight
.
If the state_id
doesn’t exist an error is raised. Read moresource§unsafe fn set_final_unchecked<S: Into<W>>(
&mut self,
state_id: StateId,
final_weight: S
)
unsafe fn set_final_unchecked<S: Into<W>>( &mut self, state_id: StateId, final_weight: S )
Set the final weight of the state with state if
state_id
. Read moresource§fn add_state(&mut self) -> StateId
fn add_state(&mut self) -> StateId
Adds a new state to the current FST. The identifier of the new state is returned Read more
source§fn add_states(&mut self, n: usize)
fn add_states(&mut self, n: usize)
Add
n
states to the Fst.source§fn tr_iter_mut(&mut self, state_id: StateId) -> Result<TrsIterMut<'_, W>>
fn tr_iter_mut(&mut self, state_id: StateId) -> Result<TrsIterMut<'_, W>>
Return a mutable iterator on the
Tr
s of the state state
.source§unsafe fn tr_iter_unchecked_mut(
&mut self,
state_id: StateId
) -> TrsIterMut<'_, W>
unsafe fn tr_iter_unchecked_mut( &mut self, state_id: StateId ) -> TrsIterMut<'_, W>
source§fn del_state(&mut self, state_to_remove: StateId) -> Result<()>
fn del_state(&mut self, state_to_remove: StateId) -> Result<()>
Removes a state from an FST. It also removes all the trs starting from another state and
reaching this state. An error is raised if the state
state_id
doesn’t exist. Read moresource§fn del_states<T: IntoIterator<Item = StateId>>(
&mut self,
dstates: T
) -> Result<()>
fn del_states<T: IntoIterator<Item = StateId>>( &mut self, dstates: T ) -> Result<()>
Removes multiple states from an FST. If one of the states doesn’t exist, an error is raised. Read more
source§fn del_all_states(&mut self)
fn del_all_states(&mut self)
Remove all the states in the FST. As a result, all the trs are also removed,
as well as the start state and all the fina states. Read more
source§unsafe fn del_trs_id_sorted_unchecked(
&mut self,
state: StateId,
to_del: &[usize]
)
unsafe fn del_trs_id_sorted_unchecked( &mut self, state: StateId, to_del: &[usize] )
Remove transitions from the fst at state
state
. Transitions are specified with
their index. The to_del
vector MUST be sorted. Read moresource§fn add_tr(&mut self, source: StateId, tr: Tr<W>) -> Result<()>
fn add_tr(&mut self, source: StateId, tr: Tr<W>) -> Result<()>
Adds a transition to the FST. The transition will start in the state
source
. Read moresource§unsafe fn add_tr_unchecked(&mut self, source: StateId, tr: Tr<W>)
unsafe fn add_tr_unchecked(&mut self, source: StateId, tr: Tr<W>)
Adds a transition to the FST. The transition will start in the state
state
. Read moresource§unsafe fn set_trs_unchecked(&mut self, source: StateId, trs: Vec<Tr<W>>)
unsafe fn set_trs_unchecked(&mut self, source: StateId, trs: Vec<Tr<W>>)
Set all the
Tr
s leaving the state state
to the parameters trs
erasing
the Tr
s previously stored. Read moresource§fn delete_final_weight(&mut self, source: StateId) -> Result<()>
fn delete_final_weight(&mut self, source: StateId) -> Result<()>
Remove the final weight of a specific state.
source§unsafe fn delete_final_weight_unchecked(&mut self, source: StateId)
unsafe fn delete_final_weight_unchecked(&mut self, source: StateId)
Remove the final weight of state
state
. Read moresource§fn pop_trs(&mut self, source: StateId) -> Result<Vec<Tr<W>>>
fn pop_trs(&mut self, source: StateId) -> Result<Vec<Tr<W>>>
Remove all trs leaving a state and return them.
source§fn take_final_weight(&mut self, state_id: StateId) -> Result<Option<W>>
fn take_final_weight(&mut self, state_id: StateId) -> Result<Option<W>>
Takes the final weight out of the fst, leaving a None in its place. Read more
source§unsafe fn take_final_weight_unchecked(&mut self, state_id: StateId) -> Option<W>
unsafe fn take_final_weight_unchecked(&mut self, state_id: StateId) -> Option<W>
Takes the final weight out of the fst, leaving a None in its place.
This version leads to
undefined behaviour
if the state doesn’t exist. Read moresource§fn set_properties(&mut self, props: FstProperties)
fn set_properties(&mut self, props: FstProperties)
Set the internal properties of the Fst. All the set properties must be verified by the Fst!
source§fn set_properties_with_mask(
&mut self,
props: FstProperties,
mask: FstProperties
)
fn set_properties_with_mask( &mut self, props: FstProperties, mask: FstProperties )
Set only a subset of the internal properties of the Fst.
source§fn emplace_tr<S: Into<W>>(
&mut self,
source: StateId,
ilabel: Label,
olabel: Label,
weight: S,
nextstate: StateId
) -> Result<()>
fn emplace_tr<S: Into<W>>( &mut self, source: StateId, ilabel: Label, olabel: Label, weight: S, nextstate: StateId ) -> Result<()>
Adds a transition to the FST. The transition will start in the state
source
. Read moresource§unsafe fn emplace_tr_unchecked<S: Into<W>>(
&mut self,
state: StateId,
ilabel: Label,
olabel: Label,
weight: S,
nextstate: StateId
)
unsafe fn emplace_tr_unchecked<S: Into<W>>( &mut self, state: StateId, ilabel: Label, olabel: Label, weight: S, nextstate: StateId )
Adds a transition to the FST. The transition will start in the state
state
. Read moresource§fn closure(&mut self, closure_type: ClosureType)
fn closure(&mut self, closure_type: ClosureType)
This operation computes the concatenative closure.
If A transduces string
x
to y
with weight a
,
then the closure transduces x
to y
with weight a
,
xx
to yy
with weight a ⊗ a
, xxx
to yyy
with weight a ⊗ a ⊗ a
, etc.
If closure_star then the empty string is transduced to itself with weight 1
as well.source§fn tr_map<M: TrMapper<W>>(&mut self, mapper: &mut M) -> Result<()>
fn tr_map<M: TrMapper<W>>(&mut self, mapper: &mut M) -> Result<()>
Maps a transition using a
TrMapper
object.source§fn compute_and_update_properties(
&mut self,
mask: FstProperties
) -> Result<FstProperties>
fn compute_and_update_properties( &mut self, mask: FstProperties ) -> Result<FstProperties>
Compute the properties verified by the Fst (with a mask) and update
the internal property bits.
source§fn compute_and_update_properties_all(&mut self) -> Result<FstProperties>
fn compute_and_update_properties_all(&mut self) -> Result<FstProperties>
Compute all the properties verified by the Fst and update the internal property bits.
fn set_symts_from_fst<W2: Semiring, OF: Fst<W2>>(&mut self, other_fst: &OF)
source§fn relabel_tables(
&mut self,
old_isymbols: Option<&Arc<SymbolTable>>,
new_isymbols: &Arc<SymbolTable>,
attach_new_isymbols: bool,
old_osymbols: Option<&Arc<SymbolTable>>,
new_osymbols: &Arc<SymbolTable>,
attach_new_osymbols: bool
) -> Result<()>
fn relabel_tables( &mut self, old_isymbols: Option<&Arc<SymbolTable>>, new_isymbols: &Arc<SymbolTable>, attach_new_isymbols: bool, old_osymbols: Option<&Arc<SymbolTable>>, new_osymbols: &Arc<SymbolTable>, attach_new_osymbols: bool ) -> Result<()>
Destructively relabel the Fst with new Symbol Tables. Read more
source§impl<W: Semiring> PartialEq for VectorFst<W>
impl<W: Semiring> PartialEq for VectorFst<W>
source§impl<W: SerializableSemiring> SerializableFst<W> for VectorFst<W>
impl<W: SerializableSemiring> SerializableFst<W> for VectorFst<W>
source§fn fst_type() -> String
fn fst_type() -> String
String identifying the type of the FST. Will be used when serialiing and
deserializing an FST in binary format.
source§fn from_parsed_fst_text(parsed_fst_text: ParsedTextFst<W>) -> Result<Self>
fn from_parsed_fst_text(parsed_fst_text: ParsedTextFst<W>) -> Result<Self>
Turns a generic wFST format into the one of the wFST.
source§fn read<P: AsRef<Path>>(path_bin_fst: P) -> Result<Self>
fn read<P: AsRef<Path>>(path_bin_fst: P) -> Result<Self>
Loads an FST from a file in binary format.
source§fn write<P: AsRef<Path>>(&self, path_bin_fst: P) -> Result<()>
fn write<P: AsRef<Path>>(&self, path_bin_fst: P) -> Result<()>
Writes the FST to a file in binary format.
source§fn from_text_string(fst_string: &str) -> Result<Self>
fn from_text_string(fst_string: &str) -> Result<Self>
Deserializes a wFST in text from a path and returns a loaded wFST.
source§fn read_text<P: AsRef<Path>>(path_text_fst: P) -> Result<Self>
fn read_text<P: AsRef<Path>>(path_text_fst: P) -> Result<Self>
Deserializes a wFST in text from a path and returns a loaded wFST.
Auto Trait Implementations§
impl<W> Freeze for VectorFst<W>
impl<W> RefUnwindSafe for VectorFst<W>where
W: RefUnwindSafe,
impl<W> Send for VectorFst<W>where
W: Send,
impl<W> Sync for VectorFst<W>where
W: Send,
impl<W> Unpin for VectorFst<W>where
W: Unpin,
impl<W> UnwindSafe for VectorFst<W>where
W: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more