以下のコード行が何をするのか誰かが私に説明できるかどうか疑問に思っていましたか?
while((sample = samples.read()) != null)
最初sample
に の次の行と等しく設定してから、samples
空でないことを確認しますか?
これはより一般的な質問ですが、誰かが OpenNLP の優れたチュートリアルを持っている場合は、それも非常にありがたいです。
メソッド全体は次のとおりです。
public static Dictionary buildNGramDictionary(ObjectStream samples, int cutoff) throws IOException {
NGramModel ngramModel = new NGramModel();
POSSample sample;
while((sample = samples.read()) != null) {
String[] words = sample.getSentence();
if (words.length > 0)
ngramModel.add(new StringList(words), 1, 1);
}
ngramModel.cutoff(cutoff, Integer.MAX_VALUE);
return ngramModel.toDictionary(true);
}