私は Lucene を初めて使用します。インデックスにバイグラムとトライグラムのトークンを含める方法の例を教えていただければ幸いです。
私は次のコードを使用しており、用語の頻度と重みを計算できるように修正しましたが、バイグラムとトリグラムにもそれを行う必要があります。トークナイゼーションの部分が見えない!私はオンラインで検索しましたが、推奨されていないクラスのいくつかは Lucene 3.4.0 には存在しません。
何か提案はありますか?
ありがとう、もえ
編集: - - - - - - - - - - - - - - - -
今、mbonaci が提案したように NGramTokenFilter を使用しています。これは、テキストをトークン化して uni、bi、および trigram を取得するコードの一部です。しかし、それは単語レベルではなく文字で行われています.
代わりに:
[H][e][l][l][o][HE][EL]
など
を探しています:[Hello][World][Hello World]
int min =1;
int max =3;
WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_34);
String text ="hello my world";
TokenStream tokenStream = analyzer.tokenStream("Data", new StringReader(text));
NGramTokenFilter myfilter = new NGramTokenFilter(tokenStream,min,max);
OffsetAttribute offsetAttribute2 = myfilter.addAttribute(OffsetAttribute.class);
CharTermAttribute charTermAttribute2 = myfilter.addAttribute(CharTermAttribute.class)
while (myfilter.incrementToken()) {
int startOffset = offsetAttribute2.startOffset();
int endOffset = offsetAttribute2.endOffset();
String term = charTermAttribute2.toString();
System.out.println(term);
};