@Override
public Decision disambiguate(AmbiguousWord target,
ArrayList<AmbiguousWord> window) throws Exception {
System.out.print(".");
Decision decision=new Decision(target,window);
// TODO Auto-generated method stub
if(target.getSenses().size()>1)
{
Classifier c;
if(this.getValue("classifier")==null)
this.addParameters("classifier:gannuCF.classifiers.NaiveBayes;");
File f=new File("./data/classifiers/"+this.dict.getCompleteName()+"/"+Dictionary.normalizeLemmaforFile(target.getLemma())+"_"+this.getValue("classifier")+".gcl");
if(f.exists())
{
c=(Classifier)Util.loadObject(f);
}
else
{
c=(Classifier)Class.forName(this.getValue("classifier")).newInstance();
c.addParameters(this.getParameterString());
c.train(target);
File dir=new File("./data/classifiers/"+this.dict.getCompleteName()+"/");
if(!dir.exists())
dir.mkdirs();
Util.writeObject(f, c);
}
ArrayList<String> sample=new ArrayList<String>(window.size());
for(AmbiguousWord word:window)
{
sample.add(word.getLemma());
}
float w[]=c.classify(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()))
if(!dwords.contains(word.getLemma()))
dwords.add(word.getLemma());
}
dwords.trimToSize();
decision.setSense(j, w[j], dwords);
}
}
else
{
decision.setSense(0, 1.0, new ArrayList<String>());
}
decision.calculateAnswer();
return decision;
}