I was wondering if someone could explain to me what the line of code below does?
while((sample = samples.read()) != null)
Does it first set sample
equal to the next line of samples
, and then check to make sure it's not empty?
This is more a general question, but if anyone has a good tutorial for OpenNLP, I would really appreciate that, as well.
Here is the method in its entirety:
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);
}
The evaluation of the expression is dictated by operator precedence.
The expression inside the brackets (sample = samples.read())
is evaluated first because the ()
brackets have a higher precedence than the !=