@@ -251,8 +251,8 @@ private CharsRef newStem(char[] buffer, int length, IntsRef forms, int formID) {
251
251
* @param previous previous affix that was removed (so we dont remove same one twice)
252
252
* @param prevFlag Flag from a previous stemming step that need to be cross-checked with any
253
253
* affixes in this recursive step
254
- * @param prefixFlag flag of the most inner removed prefix, so that when removing a suffix, it's
255
- * also checked against the word
254
+ * @param prefixId ID of the most inner removed prefix, so that when removing a suffix, it's also
255
+ * checked against the word
256
256
* @param recursionDepth current recursiondepth
257
257
* @param doPrefix true if we should remove prefixes
258
258
* @param doSuffix true if we should remove suffixes
@@ -270,7 +270,7 @@ private List<CharsRef> stem(
270
270
int length ,
271
271
int previous ,
272
272
int prevFlag ,
273
- int prefixFlag ,
273
+ int prefixId ,
274
274
int recursionDepth ,
275
275
boolean doPrefix ,
276
276
boolean doSuffix ,
@@ -398,7 +398,7 @@ private List<CharsRef> stem(
398
398
strippedWord ,
399
399
strippedWord .length ,
400
400
suffix ,
401
- prefixFlag ,
401
+ prefixId ,
402
402
recursionDepth ,
403
403
false ,
404
404
circumfix ,
@@ -474,9 +474,9 @@ private boolean checkCondition(
474
474
* @param strippedWord Word the affix has been removed and the strip added
475
475
* @param length valid length of stripped word
476
476
* @param affix HunspellAffix representing the affix rule itself
477
- * @param prefixFlag when we already stripped a prefix, we cant simply recurse and check the
478
- * suffix, unless both are compatible so we must check dictionary form against both to add it
479
- * as a stem!
477
+ * @param prefixId when we already stripped a prefix, we cant simply recurse and check the suffix,
478
+ * unless both are compatible so we must check dictionary form against both to add it as a
479
+ * stem!
480
480
* @param recursionDepth current recursion depth
481
481
* @param prefix true if we are removing a prefix (false if it's a suffix)
482
482
* @return List of stems for the word, or an empty list if none are found
@@ -485,40 +485,37 @@ private List<CharsRef> applyAffix(
485
485
char [] strippedWord ,
486
486
int length ,
487
487
int affix ,
488
- int prefixFlag ,
488
+ int prefixId ,
489
489
int recursionDepth ,
490
490
boolean prefix ,
491
491
boolean circumfix ,
492
492
boolean caseVariant )
493
493
throws IOException {
494
494
char flag = dictionary .affixData (affix , Dictionary .AFFIX_FLAG );
495
- char append = dictionary .affixData (affix , Dictionary .AFFIX_APPEND );
496
495
497
496
List <CharsRef > stems = new ArrayList <>();
498
497
499
498
IntsRef forms = dictionary .lookupWord (strippedWord , 0 , length );
500
499
if (forms != null ) {
501
500
for (int i = 0 ; i < forms .length ; i += formStep ) {
502
501
char [] wordFlags = dictionary .decodeFlags (forms .ints [forms .offset + i ], scratch );
503
- if (Dictionary .hasFlag (wordFlags , flag )) {
502
+ if (Dictionary .hasFlag (wordFlags , flag ) || isFlagAppendedByAffix ( prefixId , flag ) ) {
504
503
// confusing: in this one exception, we already chained the first prefix against the
505
504
// second,
506
505
// so it doesnt need to be checked against the word
507
506
boolean chainedPrefix = dictionary .complexPrefixes && recursionDepth == 1 && prefix ;
508
- if (!chainedPrefix
509
- && prefixFlag >= 0
510
- && !Dictionary .hasFlag (wordFlags , (char ) prefixFlag )) {
511
- // see if we can chain prefix thru the suffix continuation class (only if it has any!)
512
- if (!dictionary .hasFlag (append , (char ) prefixFlag , scratch )) {
507
+ if (!chainedPrefix && prefixId >= 0 ) {
508
+ char prefixFlag = dictionary .affixData (prefixId , Dictionary .AFFIX_FLAG );
509
+ if (!Dictionary .hasFlag (wordFlags , prefixFlag )
510
+ && !isFlagAppendedByAffix (affix , prefixFlag )) {
513
511
continue ;
514
512
}
515
513
}
516
514
517
515
// if circumfix was previously set by a prefix, we must check this suffix,
518
516
// to ensure it has it, and vice versa
519
517
if (dictionary .circumfix != -1 ) {
520
- boolean suffixCircumfix =
521
- dictionary .hasFlag (append , (char ) dictionary .circumfix , scratch );
518
+ boolean suffixCircumfix = isFlagAppendedByAffix (affix , (char ) dictionary .circumfix );
522
519
if (circumfix != suffixCircumfix ) {
523
520
continue ;
524
521
}
@@ -541,14 +538,14 @@ private List<CharsRef> applyAffix(
541
538
// if a circumfix flag is defined in the dictionary, and we are a prefix, we need to check if we
542
539
// have that flag
543
540
if (dictionary .circumfix != -1 && !circumfix && prefix ) {
544
- circumfix = dictionary . hasFlag ( append , (char ) dictionary .circumfix , scratch );
541
+ circumfix = isFlagAppendedByAffix ( affix , (char ) dictionary .circumfix );
545
542
}
546
543
547
544
if (isCrossProduct (affix ) && recursionDepth <= 1 ) {
548
545
boolean doPrefix ;
549
546
if (recursionDepth == 0 ) {
550
547
if (prefix ) {
551
- prefixFlag = flag ;
548
+ prefixId = affix ;
552
549
doPrefix = dictionary .complexPrefixes && dictionary .twoStageAffix ;
553
550
// we took away the first prefix.
554
551
// COMPLEXPREFIXES = true: combine with a second prefix and another suffix
@@ -564,7 +561,7 @@ private List<CharsRef> applyAffix(
564
561
} else {
565
562
doPrefix = false ;
566
563
if (prefix && dictionary .complexPrefixes ) {
567
- prefixFlag = flag ;
564
+ prefixId = affix ;
568
565
// we took away the second prefix: go look for another suffix
569
566
} else if (prefix || dictionary .complexPrefixes || !dictionary .twoStageAffix ) {
570
567
return stems ;
@@ -578,7 +575,7 @@ private List<CharsRef> applyAffix(
578
575
length ,
579
576
affix ,
580
577
flag ,
581
- prefixFlag ,
578
+ prefixId ,
582
579
recursionDepth + 1 ,
583
580
doPrefix ,
584
581
true ,
@@ -590,6 +587,12 @@ private List<CharsRef> applyAffix(
590
587
return stems ;
591
588
}
592
589
590
+ private boolean isFlagAppendedByAffix (int affixId , char flag ) {
591
+ if (affixId < 0 ) return false ;
592
+ int appendId = dictionary .affixData (affixId , Dictionary .AFFIX_APPEND );
593
+ return dictionary .hasFlag (appendId , flag , scratch );
594
+ }
595
+
593
596
private boolean isCrossProduct (int affix ) {
594
597
return (dictionary .affixData (affix , Dictionary .AFFIX_CONDITION ) & 1 ) == 1 ;
595
598
}
0 commit comments