for (int phraseLength : frequencyClass.validPhraseLengths(max)) {
int endOfPhrase = startOfPhrase + phraseLength;
Phrase phrase = new ContiguousPhrase(
startOfPhrase,
endOfPhrase,
corpus);
frequentPhrases.add(new Counted<Phrase>(phrase, frequency));
if (frequentPhrases.size() > maxPhrases) {
Counted<Phrase> pruned = frequentPhrases.poll();
int prunedFrequency = pruned.getCount();
prunedFrequencies.add(prunedFrequency);
if (logger.isLoggable(Level.FINER)) logger.info("Pruned " + pruned.getElement() + " with frequency " + prunedFrequency);
break;
}
}
} else if (logger.isLoggable(Level.FINER)) {
logger.finer("Skipping pruned frequency " + frequency);
}
}
while (! frequentPhrases.isEmpty() && prunedFrequencies.contains(frequentPhrases.peek().getCount())) {
Counted<Phrase> pruned = frequentPhrases.poll();
if (logger.isLoggable(Level.FINER)) logger.finer("Pruned " + pruned.getElement() + " " + pruned.getCount());
}
Counted<Phrase>[] reverse = new Counted[frequentPhrases.size()];
{
int i=frequentPhrases.size()-1;
while (! frequentPhrases.isEmpty()) {
reverse[i] = frequentPhrases.poll();
i -= 1;
}
}
LinkedHashMap<Phrase,Integer> results = new LinkedHashMap<Phrase,Integer>();
for (Counted<Phrase> countedPhrase : reverse) {
Phrase phrase = countedPhrase.getElement();
Integer count = countedPhrase.getCount();
results.put(phrase, count);
}
//
// while (! frequentPhrases.isEmpty()) {