public Decision disambiguate(AmbiguousWord target,
ArrayList<AmbiguousWord> window) throws Exception{
if(this.classifier==null)
this.classifier=this.getValue("classifier");
Decision decision=new Decision(target,window);
if(target.getSenses().size()>1)
{
Instances ins=this.loadFilteredInstances(target);
System.out.println("Trying "+target.getIndex());
Classifier cModel=null;
String Evaluator=this.getValue("evaluator");
String Search=this.getValue("search");
if(Evaluator==null)
Evaluator="";
if(Search==null)
Search="";
File f=new File("data/weka/"+this.classifier+"@"+Dictionary.normalizeLemmaforFile(target.getLemma())+"@"+Evaluator+"@"+Search+".csf");
if(f.exists())
{
cModel=(Classifier)Util.loadObject(f);
}
else
{
cModel = (Classifier)Class.forName(this.classifier).newInstance();
cModel.buildClassifier(ins);
Util.writeObject(f, cModel);
}
//Instantiate the classifier
Instance base=ins.firstInstance();
Instance sample=new Instance(base.numAttributes());
sample.setDataset(ins);
int c[]=new int[base.numAttributes()];
for(int i=0;i<base.numAttributes();i++)
{
c[i]=0;
}
for(int i=0;i<base.numAttributes();i++)
{
Attribute att=base.attribute(i);
for(AmbiguousWord word:window)
{
if(word.getLemma().equals(att.name()))
{
c[i]++;
}
}
}
for(int i=0;i<base.numAttributes();i++)
{
sample.setValue(i, ((double)c[i]));
}
double []w=cModel.distributionForInstance(sample);
for(int j=0;j<target.getSenses().size();j++)
{
ArrayList<String> dwords=new ArrayList<String>(window.size());
for(AmbiguousWord word:window)
{
if(this.overlap(target.getSenses().get(j), word.getLemma()))
dwords.add(word.getLemma());
}
decision.setSense(j, w[j], dwords);
}
}
else
decision.setSense(0, 0.1, new ArrayList<String>());
decision.calculateAnswer();
return decision;
}