diff --git a/crates/proof/src/pl/suggest.rs b/crates/proof/src/pl/suggest.rs index 101952cc0..10cfc0761 100644 --- a/crates/proof/src/pl/suggest.rs +++ b/crates/proof/src/pl/suggest.rs @@ -275,7 +275,10 @@ pub fn suggest_in(d: &AffixDict, word: &str, max: usize) -> Vec { 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(); diff --git a/crates/proof/src/pl/test_dict.rs b/crates/proof/src/pl/test_dict.rs index 4bd16d4c8..80c1aa244 100644 --- a/crates/proof/src/pl/test_dict.rs +++ b/crates/proof/src/pl/test_dict.rs @@ -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