这种转换由 处理GermanNormalizationFilter
,而不是词干分析器。真正理解一门课程并不难(与许多词干分析器不同),如果我理解正确,看起来单行更改会让你想要你想要的:
public final class CustomGermanNormalizationFilter extends TokenFilter {
// FSM with 3 states:
private static final int N = 0; /* ordinary state */
private static final int V = 1; /* stops 'u' from entering umlaut state */
private static final int U = 2; /* umlaut state, allows e-deletion */
private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
public CustomGermanNormalizationFilter(TokenStream input) {
super(input);
}
@Override
public boolean incrementToken() throws IOException {
if (input.incrementToken()) {
int state = N;
char buffer[] = termAtt.buffer();
int length = termAtt.length();
for (int i = 0; i < length; i++) {
final char c = buffer[i];
switch(c) {
//Removing this case should prevent e-deletion for "ae"
// case 'a':
case 'o':
state = U;
break;
case 'u':
state = (state == N) ? U : V;
break;
case 'e':
if (state == U)
length = StemmerUtil.delete(buffer, i--, length);
state = V;
break;
case 'i':
case 'q':
case 'y':
state = V;
break;
case 'ä':
buffer[i] = 'a';
state = V;
break;
case 'ö':
buffer[i] = 'o';
state = V;
break;
case 'ü':
buffer[i] = 'u';
state = V;
break;
case 'ß':
buffer[i++] = 's';
buffer = termAtt.resizeBuffer(1+length);
if (i < length)
System.arraycopy(buffer, i, buffer, i+1, (length-i));
buffer[i] = 's';
length++;
state = N;
break;
default:
state = N;
}
}
termAtt.setLength(length);
return true;
} else {
return false;
}
}
}
使用它代替german_normalization
应该可以解决问题。