Я должен проанализировать полный текст, прежде чем использовать другие фильтры токенов.Дело в том, что когда поток токенов заканчивается, сбросить поток невозможно.Следующий код вызывает исключение: «Нарушение контракта TokenStream: вызов метода reset () / close () отсутствует, метод reset () вызывается несколько раз, или подкласс не вызывает super.reset (). См. Javadocs класса TokenStream для получения дополнительной информации оправильный рабочий процесс ".
public class LemmatizerFilter extends TokenFilter {
private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
private final KeywordAttribute keywordAttr = addAttribute(KeywordAttribute.class);
private static ArrayList<Tag> tags;
public LemmatizerFilter(TokenStream input) {
super(input);
tags = new ArrayList<Tag>();
}
@Override
public synchronized boolean incrementToken() throws IOException {
assert tags != null;
if(tags.size() == 0) {
ArrayList<String> terms = new ArrayList<String>();
while(input.incrementToken()) {
terms.add(termAtt.toString());
}
TaggerSingleton tagger = TaggerSingleton.getInstance();
tags = tagger.tag(terms);
input.end();
input.close();
input.reset();
}
if(input.incrementToken()) { //this row raises the above exception
if (!keywordAttr.isKeyword()) {
...
}
return true;
} else {
return false;
}
}
public static ArrayList<Tag> getTags() {
return tags;
}
public static synchronized void setTags(ArrayList<Tag> tags) {
LemmatizerFilter.tags = tags;
}
}