mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 18:23:52 -06:00
Spelling: a prefix completes a suffix that needs another affix
work/US with SFX S 0 s/N: unworks is a word (the prefix completes the suffix), works isn't. The last change refused the suffix in the prefix's cross product too; a prefix that needs nothing more now completes it, as Hunspell 1.7.6 reads it. When both need another affix, neither completes the other.
This commit is contained in:
@@ -275,10 +275,12 @@ impl Dictionary {
|
||||
}
|
||||
|
||||
/// Strip suffixes from `w` (one, or two through continuation flags); `extra` flags must also be
|
||||
/// on the root, `cross` means the suffix must allow a prefix.
|
||||
fn suffixed(&self, w: &[char], extra: &[Flag], cross: bool) -> bool {
|
||||
/// on the root, `cross` means the suffix must allow a prefix. `completed`: a prefix that needs
|
||||
/// nothing more is already on the word, so a suffix that needs another affix has it
|
||||
/// (`work/US` with `SFX S 0 s/N` makes `unworks`, not `works`).
|
||||
fn suffixed(&self, w: &[char], extra: &[Flag], cross: bool, completed: bool) -> bool {
|
||||
for s in &self.sfx {
|
||||
if (cross && !s.cross) || self.only_in_compound_affix(s) || self.needs_another_affix(s) {
|
||||
if (cross && !s.cross) || self.only_in_compound_affix(s) || (self.needs_another_affix(s) && !completed) {
|
||||
continue;
|
||||
}
|
||||
let Some(stem) = strip_end(w, &s.add, &s.strip) else { continue };
|
||||
@@ -389,7 +391,7 @@ impl Dictionary {
|
||||
return true;
|
||||
}
|
||||
let w: Vec<char> = word.chars().collect();
|
||||
if self.suffixed(&w, &[], false) {
|
||||
if self.suffixed(&w, &[], false, false) {
|
||||
return true;
|
||||
}
|
||||
for p in &self.pfx {
|
||||
@@ -403,7 +405,7 @@ impl Dictionary {
|
||||
if !self.needs_another_affix(p) && self.root(&stem.iter().collect::<String>(), &[p.flag], true) {
|
||||
return true;
|
||||
}
|
||||
if p.cross && self.suffixed(&stem, &[p.flag], true) {
|
||||
if p.cross && self.suffixed(&stem, &[p.flag], true, !self.needs_another_affix(p)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1081,6 +1083,25 @@ SFX D Y 1\nSFX D 0 ed/S .\n";
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_prefix_completes_a_suffix_that_needs_another_affix() {
|
||||
// As Hunspell 1.7.6 reads it: `work/US`, a suffix needing another affix (N). The prefix
|
||||
// completes it (`unworks`); alone it doesn't (`works`); when both need another, neither
|
||||
// completes the other.
|
||||
for (pfx, good, bad) in
|
||||
[("0 un", &["work", "unwork", "unworks"][..], &["works"][..]), ("0 un/N", &["work"][..], &["works", "unwork", "unworks"][..])]
|
||||
{
|
||||
let aff = format!("NEEDAFFIX N\nPFX U Y 1\nPFX U {pfx} .\nSFX S Y 1\nSFX S 0 s/N .\n");
|
||||
let d = Dictionary::parse(aff.as_bytes(), b"1\nwork/US\n".as_slice());
|
||||
for w in good {
|
||||
assert!(d.check(w), "{pfx}: {w}");
|
||||
}
|
||||
for w in bad {
|
||||
assert!(!d.check(w), "{pfx}: {w}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlapping_compound_roots_with_a_failing_ending_stay_cheap() {
|
||||
// Roots a..aaaaaaaa overlap, so many splits of "aaa…ab" reach the same (tail, part) state; unmemoized that is millions of searches.
|
||||
|
||||
Reference in New Issue
Block a user