package gannuWSD.algorithms;
import gannuNLP.data.AmbiguousWord;
import gannuNLP.data.Input;
import gannuNLP.data.Sense;
import gannuNLP.overlapmeasures.Length;
import gannuNLP.overlapmeasures.OverlapMeasure;
import gannuWSD.testing.Decision;
import java.util.ArrayList;
/**
* Graph-based disambiguation with InDegree centrality measure as presented
* in "Unsupervised Graph-based Word Sense Disambiguation Using Measures of
* Word Semantic Similarity" by Sinha and Mihalcea.
* You can specify the OverlapMeasure by setting the parameter "scoring:gannu.overlapmeasures.yourSelectedClassName;".
*
* @author Francisco Viveros-Jiménez
*
*/
public class GraphInDegree extends WSDAlgorithm{
/**
* OverlapMeasure for calculating the overlaps.
*/
OverlapMeasure scoring;
@Override
public Decision disambiguate(AmbiguousWord target, ArrayList<AmbiguousWord> window) throws Exception
{
System.out.print(".");
ArrayList<Sense> senses=target.getSenses();
Decision decision=new Decision(target,window);
int i;
for(i=0;i<senses.size();i++)
{
double w=0;
ArrayList<String> dwords=new ArrayList<String>();
for(AmbiguousWord winword:window)
{
if(winword.getSenses().size()>0)
{
for(Sense s:winword.getSenses())
{
w+=this.scoring.calculateOverlap(senses.get(i).getBagOfWords(),s.getBagOfWords(), dwords);
}
}
else
{
if(senses.get(i).getBagOfWords().contains(winword.getLemma()))
{
w+=1.0;
dwords.add(winword.getLemma());
}
}
}
dwords.trimToSize();
decision.setSense(i, w, dwords);
}
decision.calculateAnswer();
return decision;
}
public GraphInDegree()
{
super();
this.name="GraphInDegree";
}
@Override
public void init(Input document)throws Exception {
System.out.println();
if(this.getValue("scoring")==null)
{
this.scoring=(OverlapMeasure)new Length();
}
else
{
this.scoring=(OverlapMeasure)Class.forName(this.getValue("scoring")).newInstance();
}
}
public boolean IsUseful(AmbiguousWord target, AmbiguousWord windowWord)
throws Exception {
ArrayList<String> dwords=new ArrayList<String>();
for(Sense t:target.getSenses())
{
for(Sense s:windowWord.getSenses())
{
if(this.scoring.calculateOverlap(t.getBagOfWords(), s.getBagOfWords(), dwords)>0.0)
return true;
}
}
return false;
}
}