Skip to main content

PhoneticStateSource

Struct PhoneticStateSource 

Source
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 trie
  • product_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>
where D: Dictionary + Clone + Send + Sync, D::Node: Send + Sync, <D::Node as DictionaryNode>::Unit: Into<char> + TryFrom<char> + Copy + Send + Sync,

Source

pub fn new(dictionary: &D, nfa: NFAChar, max_distance: u8) -> Self

Create a new phonetic state source.

§Arguments
  • dictionary: The dictionary to search
  • nfa: The phonetic NFA pattern
  • max_distance: Maximum edit distance for matches
Source

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 search
  • nfa: The phonetic NFA pattern
  • max_distance: Maximum edit distance for matches
  • phonetic_weight: Cost for phonetic transformations
Source

pub fn max_distance(&self) -> u8

Get the maximum edit distance.

Source

pub fn phonetic_weight(&self) -> f64

Get the phonetic weight.

Trait Implementations§

Source§

impl<D> Clone for PhoneticStateSource<D>
where D: Dictionary + Clone + Send + Sync + Clone, D::Node: Send + Sync + Clone, <D::Node as DictionaryNode>::Unit: Into<char> + TryFrom<char> + Copy + Send + Sync,

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<D> StateSource<char, TropicalWeight> for PhoneticStateSource<D>
where D: Dictionary + Clone + Send + Sync, D::Node: Send + Sync, <D::Node as DictionaryNode>::Unit: Into<char> + TryFrom<char> + Copy + Send + Sync,

Available on crate feature phonetic-rules only.
Source§

fn compute_state(&self, state: StateId) -> LazyState<char, TropicalWeight>

Compute the state information for a given state ID. Read more
Source§

fn start(&self) -> StateId

Get the start state ID.
Source§

fn num_states_hint(&self) -> Option<usize>

Get an upper bound on the number of states. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V