Lucene 3.0 では、next() メソッドが削除されました。ここで、incrementToken を使用してトークンを反復処理する必要があります。入力ストリームの最後に到達すると、false が返されます。各トークンを取得するには、 AttributeSourceクラスのメソッドを使用する必要があります。取得する属性 (ターム、タイプ、ペイロードなど) に応じて、addAttribute メソッドを使用して、対応する属性のクラス タイプをトークナイザーに追加する必要があります。
次の部分的なコード サンプルは、Lucene のソース コードをダウンロードすると見つかる WikipediaTokenizer のテスト クラスからのものです。
...
WikipediaTokenizer tf = new WikipediaTokenizer(new StringReader(test));
int count = 0;
int numItalics = 0;
int numBoldItalics = 0;
int numCategory = 0;
int numCitation = 0;
TermAttribute termAtt = tf.addAttribute(TermAttribute.class);
TypeAttribute typeAtt = tf.addAttribute(TypeAttribute.class);
while (tf.incrementToken()) {
String tokText = termAtt.term();
//System.out.println("Text: " + tokText + " Type: " + token.type());
String expectedType = (String) tcm.get(tokText);
assertTrue("expectedType is null and it shouldn't be for: " + tf.toString(), expectedType != null);
assertTrue(typeAtt.type() + " is not equal to " + expectedType + " for " + tf.toString(), typeAtt.type().equals(expectedType) == true);
count++;
if (typeAtt.type().equals(WikipediaTokenizer.ITALICS) == true){
numItalics++;
} else if (typeAtt.type().equals(WikipediaTokenizer.BOLD_ITALICS) == true){
numBoldItalics++;
} else if (typeAtt.type().equals(WikipediaTokenizer.CATEGORY) == true){
numCategory++;
}
else if (typeAtt.type().equals(WikipediaTokenizer.CITATION) == true){
numCitation++;
}
}
...