pub struct PhoneticStateSource<D>where
D: Dictionary + Clone + Send + Sync,
D::Node: Send + Sync,
<D::Node as DictionaryNode>::Unit: Into<char> + TryFrom<char> + Copy + Send + Sync,{ /* private fields */ }Expand description
State source for phonetic WFST composition.
This implements lling-llang’s StateSource trait using the phonetic
product automaton (NFA × Levenshtein). States are computed on-demand as
the composed transducer is traversed.
§Product State Representation
Each WFST state represents a tuple:
dictionary_node_id: Position in the dictionary trieproduct_state_id: ID of the phonetic product state (NFA × Levenshtein)
§Example
ⓘ
use liblevenshtein::wfst::PhoneticStateSource;
use liblevenshtein::dictionary::dynamic_dawg_char::DynamicDawgChar;
use liblevenshtein::phonetic::nfa::compile;
use liblevenshtein::phonetic::regex::parse;
use lling_llang::prelude::*;
let dict = DynamicDawgChar::from_terms(vec!["phone", "fone", "phon"]);
let nfa = compile(&parse("(ph|f)one").unwrap()).unwrap();
let source = PhoneticStateSource::new(&dict, nfa, 2);
// Use with LazyWfstWrapper for composition
let lazy_wfst = LazyWfstWrapper::new(source);Implementations§
Source§impl<D> PhoneticStateSource<D>
impl<D> PhoneticStateSource<D>
Sourcepub fn new(dictionary: &D, nfa: NFAChar, max_distance: u8) -> Self
pub fn new(dictionary: &D, nfa: NFAChar, max_distance: u8) -> Self
Create a new phonetic state source.
§Arguments
dictionary: The dictionary to searchnfa: The phonetic NFA patternmax_distance: Maximum edit distance for matches
Sourcepub fn with_phonetic_weight(
dictionary: &D,
nfa: NFAChar,
max_distance: u8,
phonetic_weight: f64,
) -> Self
pub fn with_phonetic_weight( dictionary: &D, nfa: NFAChar, max_distance: u8, phonetic_weight: f64, ) -> Self
Create a new phonetic state source with custom phonetic weight.
§Arguments
dictionary: The dictionary to searchnfa: The phonetic NFA patternmax_distance: Maximum edit distance for matchesphonetic_weight: Cost for phonetic transformations
Sourcepub fn max_distance(&self) -> u8
pub fn max_distance(&self) -> u8
Get the maximum edit distance.
Sourcepub fn phonetic_weight(&self) -> f64
pub fn phonetic_weight(&self) -> f64
Get the phonetic weight.
Trait Implementations§
Source§impl<D> Clone for PhoneticStateSource<D>
impl<D> Clone for PhoneticStateSource<D>
Source§fn clone(&self) -> PhoneticStateSource<D>
fn clone(&self) -> PhoneticStateSource<D>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<D> StateSource<char, TropicalWeight> for PhoneticStateSource<D>
Available on crate feature phonetic-rules only.
impl<D> StateSource<char, TropicalWeight> for PhoneticStateSource<D>
Available on crate feature
phonetic-rules only.Source§fn compute_state(&self, state: StateId) -> LazyState<char, TropicalWeight>
fn compute_state(&self, state: StateId) -> LazyState<char, TropicalWeight>
Compute the state information for a given state ID. Read more
Auto Trait Implementations§
impl<D> Freeze for PhoneticStateSource<D>
impl<D> RefUnwindSafe for PhoneticStateSource<D>
impl<D> Send for PhoneticStateSource<D>
impl<D> Sync for PhoneticStateSource<D>
impl<D> Unpin for PhoneticStateSource<D>
impl<D> UnsafeUnpin for PhoneticStateSource<D>
impl<D> UnwindSafe for PhoneticStateSource<D>
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