use crate::dict::PinyinDict;
use crate::fuzzy::FuzzyConfig;
pub struct PinyinEngine {
dict: PinyinDict,
fuzzy: FuzzyConfig,
}
impl PinyinEngine {
pub fn new() -> Self {
Self {
dict: PinyinDict::embedded(),
fuzzy: FuzzyConfig::strict(),
}
}
pub fn with_fuzzy(fuzzy: FuzzyConfig) -> Self {
Self {
dict: PinyinDict::embedded(),
fuzzy,
}
}
pub fn dict(&self) -> &PinyinDict {
&self.dict
}
pub fn fuzzy(&self) -> FuzzyConfig {
self.fuzzy
}
}
impl Default for PinyinEngine {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn new_loads_dict() {
let e = PinyinEngine::new();
assert!(e.dict().len() >= 50);
}
#[test]
fn with_fuzzy_keeps_dict() {
let e = PinyinEngine::with_fuzzy(FuzzyConfig::permissive());
assert!(e.dict().len() >= 50);
assert!(e.fuzzy().z_zh);
}
}