I want to generate ngram characters for a string. Below is the Lucene 4.1 lib I used for it.
Reader reader = new StringReader(text);
NGramTokenizer gramTokenizer = new NGramTokenizer(reader, 3, 5); //catch contiguous sequence of 3, 4 and 5 characters
CharTermAttribute charTermAttribute = gramTokenizer.addAttribute(CharTermAttribute.class);
while (gramTokenizer.incrementToken()) {
String token = charTermAttribute.toString();
System.out.println(token);}
However, I want to use Lucene 5.0.0 to do it. The NGramTokenizer changes a lot in Lucene 5.0.0 from the previous version, refer to http://lucene.apache.org/core/5_0_0/analyzers-common/index.html?org/apache/lucene/analysis/ngram/NGramTokenizer.html.
Anyone knows how to use Lucene 5.0.0 to do ngrams?
The following code:
will produce: