使用luxene 4.7删除stopWords

时间:2014-04-07 15:09:43

标签: java lucene

我必须从字符串中删除一个stopWord。我写了一个程序,但它引发了异常。 错误:

  

AWT-EventQueue-0“java.lang.IllegalStateException:TokenStream合同违规:reset()/ close()调用缺失,reset()多次调用,或者子类不调用super.reset()。请参阅Javadocs有关正确消费工作流程的更多信息,请参阅TokenStream类。

我不明白出了什么问题。

代码是:

 public String StopWordString(String incoming) throws IOException{

    tokenizer = new StandardTokenizer(Version.LUCENE_47,new StringReader(incoming));

    standardFilter = new StandardFilter(Version.LUCENE_47, tokenizer);
    stopFilter = new StopFilter(Version.LUCENE_47, standardFilter, StopAnalyzer.ENGLISH_STOP_WORDS_SET);

    charTermAttribute = tokenizer.addAttribute(CharTermAttribute.class);

    stopFilter.reset();

    while(stopFilter.incrementToken()) { <--the error is in this line by the neatbeans
        final String token = charTermAttribute.toString().toString();
        list.add(token);
    }

    stopFilter.end();
    stopFilter.close();

    for(i=0; i<list.size(); i++){
        str += list.get(i)+" ";
    } 

    return str;
}

0 个答案:

没有答案
相关问题