저는 Lucene을 처음 접했고 인덱스에서 bigrams와 trigrams 토큰을 갖는 방법에 대한 예제를 정말 고맙게 생각합니다.Lucene 3.4.0에서 bigram/trigrams 색인을 만드는 방법은 무엇입니까?
다음 코드를 사용 중이며 용어와 빈도를 계산할 수 있도록 수정했지만 bigrams와 trigram에도이 작업을 수행해야합니다. 토큰 화 부분을 볼 수 없습니다! 나는 온라인에서 검색을했고 추천 클래스의 일부는 Lucene 3.4.0에 존재하지 않는다.
제안 사항을 알려주십시오.
감사합니다, 모에
편집 : --------------------------------
이제 mbonaci가 제안한대로 NGramTokenFilter를 사용하고 있습니다. 이것은 유니 코드, 바이 및 트라이 그램을 얻기 위해 텍스트를 토큰 화하는 코드의 일부입니다. 그러나 그것은 단어 수준이 아닌 인물에서 이루어지고 있습니다. 대신
: [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);
};
고마워,이 사람이 일을했다. – user849934