Improve Polish spelling suggestions for final consonant devoicing (#1298)

Co-authored-by: neronek22 <aantoszek@gmail.com>
This commit is contained in:
neronek22
2026-10-14 18:17:07 -04:00
committed by GitHub
co-authored by neronek22
parent 40cf85c25b
commit ae8048e3f1
2 changed files with 18 additions and 2 deletions
+11 -1
View File
@@ -275,7 +275,10 @@ pub fn suggest_in(d: &AffixDict, word: &str, max: usize) -> Vec<String> {
if let Some(x) = v.get_mut(i) {
*x = c;
}
col.offer(&s(&v), COST_MISTYPE);
// Final devoicing can make a voiced consonant sound voiceless.
let final_devoicing = i == n - 1 && matches!((chars[i], c), ('p', 'b') | ('t', 'd') | ('k', 'g'));
let cost = if final_devoicing { COST_ADD_DIACRITIC - 1 } else { COST_MISTYPE };
col.offer(&s(&v), cost);
}
}
}
@@ -389,6 +392,13 @@ mod tests {
has("dziewczyan", "dziewczyna");
}
#[test]
fn voiced_consonant_suggestion_ranks_first() {
crate::pl::test_dict::install();
let result = suggest("chlep", 6);
assert_eq!(result.first().map(String::as_str), Some("chleb"), "{result:?}");
}
#[test]
fn the_likeliest_fix_comes_first() {
crate::pl::test_dict::install();
+7 -1
View File
@@ -33,10 +33,16 @@ PFX N 0 nie .
";
/// Stems (the count line first, as in Hunspell files).
pub const DIC: &str = "63
pub const DIC: &str = "69
źdźbło
gżegżółka
chrząszcz
chleb
chłep
chlap
chlip
chlup
chlej
pięćdziesięciu
rzeka
którzy