try {
// assessing each sense of the candidate
for (Anchor.Sense sense : candidate.getAnchor().getSenses()) {
Candidate candidateCopy = candidate.getCopy();
double senseProbablity = sense.getProbability();
if (senseProbablity < minSenseProbability)
break;
// if unambiguous, add immidiately
if (senseProbablity == 1.0) {
id = sense.getId() + "";
candidateCopy.setName(id);
candidateCopy.setTitle(sense.getTitle());
candidateCopy.setArticle(sense);
if (disambiguatedTopics.containsKey(id)) {
Candidate previousCandidate = disambiguatedTopics
.get(id);
// update the values of the previous candidate by
// the values of the new one
// System.out.println("WAS1 " +
// previousCandidate.getInfo());
// System.out.println("MRG1 " +
// candidateCopy.getInfo());
candidateCopy.mergeWith(previousCandidate);
// System.out.println("NOW1 " +
// candidateCopy.getInfo());
}
disambiguatedTopics.put(id, candidateCopy);
// else resolve ambiguity
} else {
// to avoid multiplication by 0
// in cases where an ngram is never an anchor text
// but appears as a title of Wikipedia page
if (senseProbablity == 0) {
senseProbablity = minSenseProbability;
}
double semanticRelatedness = 0;
try {
// compute the relatedness to context and the
// commonness of the meaning
semanticRelatedness = getRelatednessTo(sense,
context);
} catch (Exception e) {
System.err
.println("Error computing semantic relatedness for the sense "
+ sense);
e.printStackTrace();
}
// final score
double disambiguationScore = senseProbablity
* semanticRelatedness;
if (disambiguationScore > 0.01) {
// this is a valid sense (there may be more than
// one)
id = sense.getId() + "";
candidateCopy.setName(id);
candidateCopy.setTitle(sense.getTitle());
candidateCopy.setArticle(sense);
if (disambiguatedTopics.containsKey(id)) {
Candidate previousCandidate = disambiguatedTopics
.get(id);
// update the values of the previous candidate
// by the values of the new one
// System.out.println("WAS2 " +
// previousCandidate.getInfo());