@@ -52,14 +52,14 @@ final class Stemmer {
52
52
*/
53
53
public Stemmer (Dictionary dictionary ) {
54
54
this .dictionary = dictionary ;
55
+ prefixReader = dictionary .prefixes == null ? null : dictionary .prefixes .getBytesReader ();
56
+ suffixReader = dictionary .suffixes == null ? null : dictionary .suffixes .getBytesReader ();
55
57
for (int level = 0 ; level < 3 ; level ++) {
56
58
if (dictionary .prefixes != null ) {
57
59
prefixArcs [level ] = new FST .Arc <>();
58
- prefixReaders [level ] = dictionary .prefixes .getBytesReader ();
59
60
}
60
61
if (dictionary .suffixes != null ) {
61
62
suffixArcs [level ] = new FST .Arc <>();
62
- suffixReaders [level ] = dictionary .suffixes .getBytesReader ();
63
63
}
64
64
}
65
65
formStep = dictionary .formStep ();
@@ -252,13 +252,12 @@ private CharsRef newStem(char[] buffer, int length, IntsRef forms, int formID) {
252
252
}
253
253
254
254
// some state for traversing FSTs
255
- private final FST .BytesReader [] prefixReaders = new FST .BytesReader [3 ];
255
+ private final FST .BytesReader prefixReader ;
256
+ private final FST .BytesReader suffixReader ;
256
257
257
258
@ SuppressWarnings ({"unchecked" , "rawtypes" })
258
259
private final FST .Arc <IntsRef >[] prefixArcs = new FST .Arc [3 ];
259
260
260
- private final FST .BytesReader [] suffixReaders = new FST .BytesReader [3 ];
261
-
262
261
@ SuppressWarnings ({"unchecked" , "rawtypes" })
263
262
private final FST .Arc <IntsRef >[] suffixArcs = new FST .Arc [3 ];
264
263
@@ -302,7 +301,6 @@ private List<CharsRef> stem(
302
301
303
302
if (doPrefix && dictionary .prefixes != null ) {
304
303
FST <IntsRef > fst = dictionary .prefixes ;
305
- FST .BytesReader bytesReader = prefixReaders [recursionDepth ];
306
304
FST .Arc <IntsRef > arc = prefixArcs [recursionDepth ];
307
305
fst .getFirstArc (arc );
308
306
IntsRef NO_OUTPUT = fst .outputs .getNoOutput ();
@@ -311,7 +309,7 @@ private List<CharsRef> stem(
311
309
for (int i = 0 ; i < limit ; i ++) {
312
310
if (i > 0 ) {
313
311
int ch = word [i - 1 ];
314
- if (fst .findTargetArc (ch , arc , arc , bytesReader ) == null ) {
312
+ if (fst .findTargetArc (ch , arc , arc , prefixReader ) == null ) {
315
313
break ;
316
314
} else if (arc .output () != NO_OUTPUT ) {
317
315
output = fst .outputs .add (output , arc .output ());
@@ -351,7 +349,6 @@ private List<CharsRef> stem(
351
349
352
350
if (doSuffix && dictionary .suffixes != null ) {
353
351
FST <IntsRef > fst = dictionary .suffixes ;
354
- FST .BytesReader bytesReader = suffixReaders [recursionDepth ];
355
352
FST .Arc <IntsRef > arc = suffixArcs [recursionDepth ];
356
353
fst .getFirstArc (arc );
357
354
IntsRef NO_OUTPUT = fst .outputs .getNoOutput ();
@@ -360,7 +357,7 @@ private List<CharsRef> stem(
360
357
for (int i = length ; i >= limit ; i --) {
361
358
if (i < length ) {
362
359
int ch = word [i ];
363
- if (fst .findTargetArc (ch , arc , arc , bytesReader ) == null ) {
360
+ if (fst .findTargetArc (ch , arc , arc , suffixReader ) == null ) {
364
361
break ;
365
362
} else if (arc .output () != NO_OUTPUT ) {
366
363
output = fst .outputs .add (output , arc .output ());
0 commit comments