英語のストップ ワードを削除するために lucene を使用していますが、私の要件は英語のストップ ワードとカスタム ストップ ワードを削除することです。以下は、lucene を使用して英語のストップ ワードを削除するコードです。
私のサンプルコード:
public class Stopwords_remove {
public String removeStopWords(String string) throws IOException
{
StandardAnalyzer ana = new StandardAnalyzer(Version.LUCENE_30);
TokenStream tokenStream = new StandardTokenizer(Version.LUCENE_36,newStringReader(string));
StringBuilder sb = new StringBuilder();
tokenStream = new StopFilter(Version.LUCENE_36, tokenStream, ana.STOP_WORDS_SET);
CharTermAttribute token = tokenStream.getAttribute(CharTermAttribute.class);
while (tokenStream.incrementToken())
{
if (sb.length() > 0)
{
sb.append(" ");
}
sb.append(token.toString());
}
return sb.toString();
}
public static void main(String args[]) throws IOException
{
String text = "this is a java project written by james.";
Stopwords_remove stopwords = new Stopwords_remove();
stopwords.removeStopWords(text);
}
}
出力:java project written james.
必要な出力:java project james.
これどうやってするの?