如何使用lucene阻止印度尼西亚语

时间:2014-06-04 18:06:23

标签: java lucene stemming

我试图从库org.apache.lucene.analysis.id实现类IndonesianAnalyzer。*;现在我有一个问题如何使用初始化类indonesian分析器到我的项目,我的代码像这样?

 import java.io.*;
 import org.apache.lucene.analysis.*;
 import org.apache.lucene.analysis.snowball.*;
 import org.apache.lucene.analysis.id.*;

 public class exampleText {
public static String Stem(String text, String language){
    StringBuffer result = new StringBuffer();
    if (text!=null && text.trim().length()>0){
        StringReader tReader = new StringReader(text);
        IndonesianAnalyzer analyzer = new IndonesianAnalyzer(matchVersion);
        TokenStream tStream = analyzer.tokenStream("contents", tReader);
        TermAttribute term = tStream.addAttribute(TermAttribute.class);

        try {
            while (tStream.incrementToken()){
                result.append(term.term());
                result.append(" ");
            }
        } catch (IOException ioe){
            System.out.println("Error: "+ioe.getMessage());
        }
    }


    if (result.length()==0)
        result.append(text);
    return result.toString().trim();
 }

0 个答案:

没有答案