mod backend;
mod state_source;
mod universal_state_source;
mod universal_wrapper;
mod wrapper;
mod composed_phonetic;
#[cfg(feature = "phonetic-rules")]
mod phonetic_nfa_wfst;
mod phonetic_rewrite_wfst;
#[cfg(feature = "phonetic-rules")]
mod phonetic_state_source;
#[cfg(feature = "phonetic-rules")]
mod phonetic_wfst;
mod generalized_wfst;
mod wallbreaker_wfst;
pub use backend::DictionaryBackend;
pub use state_source::LevenshteinStateSource;
pub use universal_state_source::{UniversalLevenshteinStateSource, UniversalStateRegistry};
pub use universal_wrapper::{BoundUniversalWfst, UniversalLevenshteinWfst};
pub use wrapper::LevenshteinWfst;
pub use composed_phonetic::{PhoneticMatch, PhoneticPipelineBuilder, PhoneticPipelineConfig};
#[cfg(feature = "phonetic-rules")]
pub use phonetic_nfa_wfst::PhoneticNfaWfst;
pub use phonetic_rewrite_wfst::{CommonPhoneticRules, RewriteRule, RewriteWfst};
#[cfg(feature = "phonetic-rules")]
pub use phonetic_state_source::PhoneticStateSource;
#[cfg(feature = "phonetic-rules")]
pub use phonetic_wfst::{PhoneticWfst, PhoneticWfstBuilder};
pub use generalized_wfst::{GeneralizedWfst, GeneralizedWfstBuilder};
pub use wallbreaker_wfst::{WallBreakerWfst, WallBreakerWfstBuilder};
pub use lling_llang::prelude::{
LazyState, LazyWfst, LazyWfstWrapper, Semiring, StateId, StateSource, TropicalWeight, VocabId,
WeightedTransition, Wfst,
};
pub mod state_encoding {
use lling_llang::wfst::StateId;
#[inline]
pub fn encode(dict_node: u32, automaton_state: u32, max_automaton_states: u32) -> StateId {
dict_node * max_automaton_states + automaton_state
}
#[inline]
pub fn decode(state_id: StateId, max_automaton_states: u32) -> (u32, u32) {
let automaton_state = state_id % max_automaton_states;
let dict_node = state_id / max_automaton_states;
(dict_node, automaton_state)
}
#[inline]
pub fn estimate_automaton_states(query_len: usize, max_distance: usize) -> u32 {
let positions = query_len + 1;
let distances = 2 * max_distance + 1;
(positions * distances) as u32
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_state_encoding_roundtrip() {
let max_states = 100u32;
for dict_node in 0..10 {
for auto_state in 0..10 {
let encoded = state_encoding::encode(dict_node, auto_state, max_states);
let (dec_dict, dec_auto) = state_encoding::decode(encoded, max_states);
assert_eq!(dec_dict, dict_node);
assert_eq!(dec_auto, auto_state);
}
}
}
#[test]
fn test_estimate_automaton_states() {
let estimate = state_encoding::estimate_automaton_states(5, 2);
assert!(estimate > 0);
assert!(estimate <= 100); }
}