@@ -140,7 +140,7 @@ private boolean checkWord(char[] wordChars, int length, WordCase originalCase) {
140
140
return false ;
141
141
}
142
142
143
- if (! stemmer . doStem (wordChars , 0 , length , originalCase , SIMPLE_WORD ). isEmpty () ) {
143
+ if (findStem (wordChars , 0 , length , originalCase , SIMPLE_WORD ) != null ) {
144
144
return true ;
145
145
}
146
146
@@ -156,25 +156,40 @@ && checkCompoundRules(wordChars, 0, length, new ArrayList<>())) {
156
156
return false ;
157
157
}
158
158
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
+
159
175
private boolean checkCompounds (
160
- CharsRef word , WordCase originalCase , int depth , Predicate <List < CharsRef > > checkPatterns ) {
176
+ CharsRef word , WordCase originalCase , int depth , Predicate <CharsRef > checkPatterns ) {
161
177
if (depth > dictionary .compoundMax - 2 ) return false ;
162
178
163
179
int limit = word .length - dictionary .compoundMin + 1 ;
164
180
for (int breakPos = dictionary .compoundMin ; breakPos < limit ; breakPos ++) {
165
181
WordContext context = depth == 0 ? COMPOUND_BEGIN : COMPOUND_MIDDLE ;
166
182
int breakOffset = word .offset + breakPos ;
167
183
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
171
186
&& dictionary .simplifiedTriple
172
187
&& 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 );
174
189
}
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 )) {
178
193
return true ;
179
194
}
180
195
}
@@ -195,12 +210,11 @@ private boolean checkCompoundPatternReplacements(
195
210
if (expanded != null ) {
196
211
WordContext context = depth == 0 ? COMPOUND_BEGIN : COMPOUND_MIDDLE ;
197
212
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 )) {
204
218
return true ;
205
219
}
206
220
}
@@ -209,28 +223,27 @@ private boolean checkCompoundPatternReplacements(
209
223
return false ;
210
224
}
211
225
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 ->
215
228
dictionary .checkCompoundPatterns .stream ()
216
- .noneMatch (p -> p .prohibitsCompounding (word , breakPos , stems , nextStems ));
229
+ .noneMatch (p -> p .prohibitsCompounding (word , breakPos , stems , nextStem ));
217
230
}
218
231
219
232
private boolean checkCompoundsAfter (
220
233
CharsRef word ,
221
234
int breakPos ,
222
235
WordCase originalCase ,
223
236
int depth ,
224
- List < CharsRef > prevStems ,
225
- Predicate <List < CharsRef > > checkPatterns ) {
237
+ CharsRef prevStem ,
238
+ Predicate <CharsRef > checkPatterns ) {
226
239
int remainingLength = word .length - breakPos ;
227
240
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 ))
232
245
&& !hasForceUCaseProblem (word .chars , breakOffset , remainingLength , originalCase )
233
- && checkPatterns .test (tailStems )) {
246
+ && checkPatterns .test (tailStem )) {
234
247
return true ;
235
248
}
236
249
0 commit comments