Expand description
§duallity — Levenshtein automata as lling-llang WFSTs.
This crate exposes liblevenshtein’s Levenshtein automata as lling-llang
Wfst implementers, enabling participation in WFST composition pipelines.
§Overview
The integration provides:
-
LevenshteinWfst: A lazy WFST wrapper that presents the Levenshtein transducer × dictionary product as aWfst<char, TropicalWeight>. States encode (dictionary_node, automaton_state) pairs. -
LevenshteinStateSource: AStateSourceimplementation for lazy state computation, enabling efficient composition without materializing the full product state space. -
DictionaryBackend: An adapter that implements lling-llang’s [LatticeBackend] trait using a liblevenshtein dictionary.
§Architecture
The Levenshtein transducer produces a weighted transducer where:
- Input: Query characters (the misspelled word)
- Output: Dictionary characters (corrections)
- Weight: Edit distance as
TropicalWeight(min-plus semiring)
State encoding uses a composite ID: state_id = dict_node * automaton_size + automaton_state
§Example
use duallity::{LevenshteinWfst, DictionaryBackend};
use libdictenstein::dynamic_dawg::char::DynamicDawgChar;
use lling_llang::composition::compose;
use lling_llang::prelude::*;
// Build a dictionary
let dict = DynamicDawgChar::from_terms(vec!["hello", "help", "world"]);
// Create a Levenshtein WFST for the query "helo" with max distance 2
let lev_wfst = LevenshteinWfst::new(&dict, "helo", 2);
// Compose with a language model WFST
let composed = compose(lev_wfst, language_model);
// Find best corrections using composed transducer
for path in composed.accepting_paths() {
println!("{:?} (weight: {:?})", path.labels(), path.weight());
}§Phonetic variants
Phonetic Levenshtein WFST variants are behind the phonetic-rules feature:
[dependencies]
duallity = { version = "0.1", features = ["phonetic-rules"] }Modules§
- state_
encoding - Composite state ID encoding for the product automaton.
Structs§
- Bound
Universal Wfst - A pre-bound Universal WFST that can be cloned efficiently.
- Common
Phonetic Rules - Builder for common phonetic rewrite rules.
- Dictionary
Backend - Adapter that exposes a liblevenshtein dictionary as a lling-llang
LatticeBackend. - Generalized
Wfst - Generalized Automaton WFST wrapper.
- Generalized
Wfst Builder - Builder for Generalized WFST.
- Lazy
Wfst Wrapper - Generic lazy WFST wrapper that computes states on demand.
- Levenshtein
State Source - State source for lazy Levenshtein WFST computation.
- Levenshtein
Wfst - A Levenshtein transducer exposed as a lling-llang WFST.
- Phonetic
Match - Result of a phonetic pipeline search.
- Phonetic
NfaWfst - A pure phonetic NFA exposed as a lling-llang WFST.
- Phonetic
Pipeline Builder - Builder for phonetic matching pipelines.
- Phonetic
Pipeline Config - Configuration for a phonetic matching pipeline.
- Phonetic
State Source - State source for phonetic WFST composition.
- Phonetic
Wfst - A phonetic transducer exposed as a lling-llang WFST.
- Phonetic
Wfst Builder - Builder for PhoneticWfst with pattern string support.
- Rewrite
Rule - A phonetic rewrite rule.
- Rewrite
Wfst - A rule-based phonetic rewrite WFST.
- Tropical
Weight - Tropical semiring weight.
- Universal
Levenshtein State Source - State source for Universal Levenshtein WFST computation.
- Universal
Levenshtein Wfst - A Universal Levenshtein transducer exposed as a lling-llang WFST.
- Universal
State Registry - State registry for deduplicating Universal Levenshtein states.
- Wall
Breaker Wfst - WallBreaker WFST wrapper.
- Wall
Breaker Wfst Builder - Builder for WallBreaker WFST.
- Weighted
Transition - A weighted transition in a WFST.
Enums§
- Lazy
State - A state that may or may not have been computed yet.
Traits§
- Lazy
Wfst - Trait for WFSTs that support lazy (on-demand) state expansion.
- Semiring
- Algebraic semiring for WFST weight operations.
- State
Source - Trait for types that can produce WFST states on demand.
- Wfst
- Core trait for immutable WFST access.