@@ -140,7 +140,7 @@ private boolean checkWord(char[] wordChars, int length, WordCase originalCase) {
140140 return false ;
141141 }
142142
143- if (! stemmer . doStem (wordChars , 0 , length , originalCase , SIMPLE_WORD ). isEmpty () ) {
143+ if (findStem (wordChars , 0 , length , originalCase , SIMPLE_WORD ) != null ) {
144144 return true ;
145145 }
146146
@@ -156,25 +156,40 @@ && checkCompoundRules(wordChars, 0, length, new ArrayList<>())) {
156156 return false ;
157157 }
158158
159+ private CharsRef findStem (
160+ char [] wordChars , int offset , int length , WordCase originalCase , WordContext context ) {
161+ CharsRef [] result = {null };
162+ stemmer .doStem (
163+ wordChars ,
164+ offset ,
165+ length ,
166+ originalCase ,
167+ context ,
168+ (stem , forms , formID ) -> {
169+ result [0 ] = stem ;
170+ return false ;
171+ });
172+ return result [0 ];
173+ }
174+
159175 private boolean checkCompounds (
160- CharsRef word , WordCase originalCase , int depth , Predicate <List < CharsRef > > checkPatterns ) {
176+ CharsRef word , WordCase originalCase , int depth , Predicate <CharsRef > checkPatterns ) {
161177 if (depth > dictionary .compoundMax - 2 ) return false ;
162178
163179 int limit = word .length - dictionary .compoundMin + 1 ;
164180 for (int breakPos = dictionary .compoundMin ; breakPos < limit ; breakPos ++) {
165181 WordContext context = depth == 0 ? COMPOUND_BEGIN : COMPOUND_MIDDLE ;
166182 int breakOffset = word .offset + breakPos ;
167183 if (mayBreakIntoCompounds (word .chars , word .offset , word .length , breakOffset )) {
168- List <CharsRef > stems =
169- stemmer .doStem (word .chars , word .offset , breakPos , originalCase , context );
170- if (stems .isEmpty ()
184+ CharsRef stem = findStem (word .chars , word .offset , breakPos , originalCase , context );
185+ if (stem == null
171186 && dictionary .simplifiedTriple
172187 && word .chars [breakOffset - 1 ] == word .chars [breakOffset ]) {
173- stems = stemmer . doStem (word .chars , word .offset , breakPos + 1 , originalCase , context );
188+ stem = findStem (word .chars , word .offset , breakPos + 1 , originalCase , context );
174189 }
175- if (! stems . isEmpty () && checkPatterns .test (stems )) {
176- Predicate <List < CharsRef >> nextCheck = checkNextPatterns (word , breakPos , stems );
177- if (checkCompoundsAfter (word , breakPos , originalCase , depth , stems , nextCheck )) {
190+ if (stem != null && checkPatterns .test (stem )) {
191+ Predicate <CharsRef > nextCheck = checkNextPatterns (word , breakPos , stem );
192+ if (checkCompoundsAfter (word , breakPos , originalCase , depth , stem , nextCheck )) {
178193 return true ;
179194 }
180195 }
@@ -195,12 +210,11 @@ private boolean checkCompoundPatternReplacements(
195210 if (expanded != null ) {
196211 WordContext context = depth == 0 ? COMPOUND_BEGIN : COMPOUND_MIDDLE ;
197212 int breakPos = pos + pattern .endLength ();
198- List <CharsRef > stems =
199- stemmer .doStem (expanded .chars , expanded .offset , breakPos , originalCase , context );
200- if (!stems .isEmpty ()) {
201- Predicate <List <CharsRef >> nextCheck =
202- next -> pattern .prohibitsCompounding (expanded , breakPos , stems , next );
203- if (checkCompoundsAfter (expanded , breakPos , originalCase , depth , stems , nextCheck )) {
213+ CharsRef stem = findStem (expanded .chars , expanded .offset , breakPos , originalCase , context );
214+ if (stem != null ) {
215+ Predicate <CharsRef > nextCheck =
216+ next -> pattern .prohibitsCompounding (expanded , breakPos , stem , next );
217+ if (checkCompoundsAfter (expanded , breakPos , originalCase , depth , stem , nextCheck )) {
204218 return true ;
205219 }
206220 }
@@ -209,28 +223,27 @@ private boolean checkCompoundPatternReplacements(
209223 return false ;
210224 }
211225
212- private Predicate <List <CharsRef >> checkNextPatterns (
213- CharsRef word , int breakPos , List <CharsRef > stems ) {
214- return nextStems ->
226+ private Predicate <CharsRef > checkNextPatterns (CharsRef word , int breakPos , CharsRef stems ) {
227+ return nextStem ->
215228 dictionary .checkCompoundPatterns .stream ()
216- .noneMatch (p -> p .prohibitsCompounding (word , breakPos , stems , nextStems ));
229+ .noneMatch (p -> p .prohibitsCompounding (word , breakPos , stems , nextStem ));
217230 }
218231
219232 private boolean checkCompoundsAfter (
220233 CharsRef word ,
221234 int breakPos ,
222235 WordCase originalCase ,
223236 int depth ,
224- List < CharsRef > prevStems ,
225- Predicate <List < CharsRef > > checkPatterns ) {
237+ CharsRef prevStem ,
238+ Predicate <CharsRef > checkPatterns ) {
226239 int remainingLength = word .length - breakPos ;
227240 int breakOffset = word .offset + breakPos ;
228- List < CharsRef > tailStems =
229- stemmer . doStem (word .chars , breakOffset , remainingLength , originalCase , COMPOUND_END );
230- if (! tailStems . isEmpty ()
231- && !(dictionary .checkCompoundDup && intersectIgnoreCase ( prevStems , tailStems ))
241+ CharsRef tailStem =
242+ findStem (word .chars , breakOffset , remainingLength , originalCase , COMPOUND_END );
243+ if (tailStem != null
244+ && !(dictionary .checkCompoundDup && equalsIgnoreCase ( prevStem , tailStem ))
232245 && !hasForceUCaseProblem (word .chars , breakOffset , remainingLength , originalCase )
233- && checkPatterns .test (tailStems )) {
246+ && checkPatterns .test (tailStem )) {
234247 return true ;
235248 }
236249
0 commit comments