Skip to content

Commit d95e405

Browse files
authored
LUCENE-9721: Hunspell: disallow ONLYINCOMPOUND suffixes at the very end of compound words (#2294)
1 parent a79f641 commit d95e405

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Stemmer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,12 @@ private boolean isAffixCompatible(
568568
if (context != allowed && !dictionary.hasFlag(append, dictionary.compoundPermit, scratch)) {
569569
return false;
570570
}
571+
if (context == WordContext.COMPOUND_END
572+
&& !isPrefix
573+
&& !previousWasPrefix
574+
&& dictionary.hasFlag(append, dictionary.onlyincompound, scratch)) {
575+
return false;
576+
}
571577
}
572578

573579
if (recursionDepth == 0) {

lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/SpellCheckerTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ public void testCompoundrule8() throws Exception {
152152
doTest("compoundrule8");
153153
}
154154

155+
public void testDisallowCompoundOnlySuffixesAtTheVeryEnd() throws Exception {
156+
doTest("onlyincompound2");
157+
}
158+
155159
public void testGermanCompounding() throws Exception {
156160
doTest("germancompounding");
157161
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# affixes only in compounds (see also fogemorpheme example)
2+
ONLYINCOMPOUND O
3+
COMPOUNDFLAG A
4+
COMPOUNDPERMITFLAG P
5+
6+
SFX B Y 1
7+
SFX B 0 s/OP .
8+
9+
# obligate fogemorpheme by forbidding the stem (0) in compounds
10+
11+
CHECKCOMPOUNDPATTERN 1
12+
CHECKCOMPOUNDPATTERN 0/B /A
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
foo/A
3+
pseudo/AB
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foo
2+
foopseudo
3+
pseudosfoo
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pseudos
2+
foopseudos
3+
pseudofoo

0 commit comments

Comments
 (0)