diff --git a/crates/proof/src/hr/suggest.rs b/crates/proof/src/hr/suggest.rs index 875bf98c7..d6f8159ac 100644 --- a/crates/proof/src/hr/suggest.rs +++ b/crates/proof/src/hr/suggest.rs @@ -52,11 +52,11 @@ impl Collector<'_> { let mut words = Vec::new(); let mut cost = cost; for part in cand.split(' ') { - if self.d.contains(part) { + if self.d.contains_suggestible(part) { words.push(part.to_string()); } else { let c = capitalize(part); - if !self.d.contains(&c) { + if !self.d.contains_suggestible(&c) { return; } words.push(c); @@ -69,6 +69,9 @@ impl Collector<'_> { /// Keep a suggestion known to be correct. fn keep(&mut self, text: String, cost: u32) { + if !text.split(' ').all(|part| self.d.can_suggest(part)) { + return; + } self.seq += 1; let seq = self.seq; let e = self.found.entry(text).or_insert((cost, seq)); @@ -348,6 +351,10 @@ fn scan(col: &mut Collector, chars: &[char]) { mod tests { use super::*; #[test] + fn nosuggest_stems_and_forms_are_never_offered() { + crate::affix::tests::assert_nosuggest_is_honoured(suggest_in); + } + #[test] fn croatian_suggestions() { crate::hr::test_dict::install(); for (wrong, right) in [("kuca", "kuća"), ("racunalo", "računalo"), ("covjek", "čovjek"), ("rijec", "riječ"), ("skolla", "škola")] { diff --git a/crates/proof/src/it/suggest.rs b/crates/proof/src/it/suggest.rs index 500d1c09d..6a043ff2b 100644 --- a/crates/proof/src/it/suggest.rs +++ b/crates/proof/src/it/suggest.rs @@ -73,11 +73,11 @@ impl Collector<'_> { let mut words = Vec::new(); let mut cost = cost; for part in cand.split(' ') { - if self.d.contains(part) { + if self.d.contains_suggestible(part) { words.push(part.to_string()); } else { let c = capitalize(part); - if !self.d.contains(&c) { + if !self.d.contains_suggestible(&c) { return; } words.push(c); @@ -90,6 +90,9 @@ impl Collector<'_> { /// Keep a suggestion known to be correct. fn keep(&mut self, text: String, cost: u32) { + if !text.split(' ').all(|part| self.d.can_suggest(part)) { + return; + } self.seq += 1; let seq = self.seq; let e = self.found.entry(text).or_insert((cost, seq)); @@ -371,6 +374,11 @@ mod tests { assert!(s.iter().any(|x| x == want), "{word} → {s:?}, want {want}"); } + #[test] + fn nosuggest_stems_and_forms_are_never_offered() { + crate::affix::tests::assert_nosuggest_is_honoured(suggest_in); + } + #[test] fn italian_misspellings_get_the_right_suggestion() { crate::it::test_dict::install(); diff --git a/crates/proof/src/ru/suggest.rs b/crates/proof/src/ru/suggest.rs index cb4c3791d..24eeb7642 100644 --- a/crates/proof/src/ru/suggest.rs +++ b/crates/proof/src/ru/suggest.rs @@ -161,11 +161,11 @@ impl Collector<'_> { let mut words = Vec::new(); let mut cost = cost; for part in cand.split(' ') { - if self.d.contains(part) { + if self.d.contains_suggestible(part) { words.push(part.to_string()); } else { let c = capitalize(part); - if !self.d.contains(&c) { + if !self.d.contains_suggestible(&c) { return; } words.push(c); @@ -178,6 +178,9 @@ impl Collector<'_> { /// Keep a suggestion known to be correct. fn keep(&mut self, text: String, cost: u32) { + if !text.split(' ').all(|part| self.d.can_suggest(part)) { + return; + } self.seq += 1; let seq = self.seq; let e = self.found.entry(text).or_insert((cost, seq)); @@ -458,6 +461,22 @@ mod tests { assert!(s.iter().any(|x| x == want), "{word} → {s:?}, want {want}"); } + /// A word the dictionary marks NOSUGGEST (a vulgarism, a rare form) is correct but never + /// offered, in any round or letter case. Russian's MAP and REP tables are its own, so the + /// shared Latin-script check doesn't reach it. + #[test] + fn nosuggest_words_are_never_offered() { + let offered = |aff: &str, input: &str| { + let d = AffixDict::from_hunspell(aff, "2\nпривет/N\nпредмет/N\n", &[]).unwrap(); + suggest_in(&d, input, 16) + }; + assert!(offered("SET UTF-8\n", "превет").contains(&"привет".into()), "offered without the flag declared"); + for input in ["превет", "ПРЕВЕТ", "предмот", "приветт", "привте", "привет"] { + let s = offered("SET UTF-8\nNOSUGGEST N\n", input); + assert!(!s.iter().any(|w| w.to_lowercase().contains("привет") || w.to_lowercase().contains("предмет")), "{input}: {s:?}"); + } + } + #[test] fn russian_misspellings_get_the_right_suggestion() { crate::ru::test_dict::install();