feat: Add hunspell dictionary support to gazetteer
Integrates the `spellbook` crate to allow for a Hunspell dictionary to be used as a veto mechanism within the gazetteer. This prevents common German words from being incorrectly rewritten to vocabulary entries if they fall within the edit distance threshold. For example, "Kaktus" will no longer be rewritten to "Lantus" if a Hunspell dictionary is provided and contains "Kaktus". The `hunspell_dict_path` configuration option is added, defaulting to `/usr/share/hunspell/de_DE`. This path should point to the stem of the Hunspell dictionary files (e.g., `/usr/share/hunspell/de_DE.aff` and `/usr/share/hunspell/de_DE.dic`). The gazetteer now supports an optional `DictChecker` trait, allowing for pluggable dictionary implementations. `SpellbookDict` is the initial implementation using the `spellbook` crate. Includes new tests to verify the dict veto functionality, including handling of case sensitivity and exact matches. An ignored test is added for live verification against system-installed Hunspell dictionaries.
This commit is contained in:
@@ -62,6 +62,12 @@ pub struct Config {
|
||||
/// medications). Loaded once at startup; a missing directory is a
|
||||
/// non-fatal WARN — analysis runs without proper-name correction.
|
||||
pub vocab_dir: PathBuf,
|
||||
/// Path prefix (without extension) to a hunspell dictionary pair
|
||||
/// `<stem>.aff` + `<stem>.dic`. Used by the gazetteer as a dict
|
||||
/// veto against false-positive rewrites (e.g. `Kaktus` → `Lantus`).
|
||||
/// Missing / unreadable files are a non-fatal WARN — the gazetteer
|
||||
/// falls back to dict-less behaviour.
|
||||
pub hunspell_dict_path: PathBuf,
|
||||
pub session_timeout_hours: u32,
|
||||
/// Whether to set the `Secure` flag on the session cookie. Default `true`.
|
||||
/// Set `COOKIE_SECURE=false` only for plain-HTTP local development —
|
||||
@@ -105,6 +111,10 @@ impl Config {
|
||||
}
|
||||
},
|
||||
vocab_dir: PathBuf::from(optional_env("VOCAB_DIR", "./vocab")),
|
||||
hunspell_dict_path: PathBuf::from(optional_env(
|
||||
"HUNSPELL_DICT",
|
||||
"/usr/share/hunspell/de_DE",
|
||||
)),
|
||||
session_timeout_hours: optional_env_parsed("SESSION_TIMEOUT_HOURS", 8),
|
||||
cookie_secure: optional_env_parsed("COOKIE_SECURE", true),
|
||||
}
|
||||
@@ -158,6 +168,7 @@ impl Config {
|
||||
llm_timeout_seconds: 180,
|
||||
llm_system_prompt: crate::analyze::prompt::SYSTEM_PROMPT.to_string(),
|
||||
vocab_dir: PathBuf::new(),
|
||||
hunspell_dict_path: PathBuf::new(),
|
||||
session_timeout_hours: 8,
|
||||
cookie_secure: false,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user