// probability
SortedVector<Article> bestCandidateSenses = new SortedVector<Article>();
for (Candidate candidate : candidates) {
Anchor anchor = candidate.getAnchor();
try {
// if required number of context articles
// is reached, break
if (context.size() >= maxContextSize) {
break;
}
if (anchor.getSenses().isEmpty()) {
continue;
}
// what is the most likely sense for the given candidate
Sense bestSense = anchor.getSenses().first();
// add to the context all articles that map
// from ngrams with one possible meaning
// = non-ambiguous meanings
// and high probability of being links in Wikipedia
if (anchor.getSenses().size() == 1
&& anchor.getLinkProbability() > 0.5) {
context.add(bestSense);
continue;
}
// in case if not enough non-ambigious terms were collected
// additionally collect other mappings based on:
// a. likelihood of the sense
double senseProbability = bestSense.getProbability();
// b. keyphraseness
double linkProbability = anchor.getLinkProbability();
if (senseProbability >= 0.9 && linkProbability > 0.5) {
bestSense.setWeight(senseProbability);
bestCandidateSenses.add(bestSense, false);
}