Package gannuWSD.testing

Examples of gannuWSD.testing.Decision


  }
   @Override
  public Decision disambiguate(AmbiguousWord target, ArrayList<AmbiguousWord> window) throws Exception
  {
    ArrayList<Sense> senses=target.getSenses();
    Decision decision=new Decision(target,window);
    int i;
    Random r=new Random();
   
   
    for(i=0;i<senses.size();i++)
    {
      ArrayList<String> dwords=new ArrayList<String>();
      decision.setSense(i, r.nextDouble(), dwords);
    }
    decision.calculateAnswer();
    return decision;
  }
View Full Code Here


   boolean osd;
   @Override
  public Decision disambiguate(AmbiguousWord target, ArrayList<AmbiguousWord> window) throws Exception
  {
    ArrayList<Sense> senses=target.getSenses();
    Decision decision=new Decision(target,window);
    int i;
    if (!osd || this.current.isOneSensePerDiscourse(target.getLemma()))
    {   
      int index=this.current.getMFS(target.getLemma());
      for(i=0;i<senses.size();i++)
      {
        ArrayList<String> dwords=new ArrayList<String>();
        if (index==i&&index>=0)
          decision.setSense(i, 1.0, dwords);
        else
          decision.setSense(i, 0.0, dwords);
      }
    }
    decision.calculateAnswer();
    return decision;
  }
View Full Code Here

  }
   @Override
  public Decision disambiguate(AmbiguousWord target, ArrayList<AmbiguousWord> window) throws Exception
  {
    ArrayList<Sense> senses=target.getSenses();
    Decision decision=new Decision(target,window);
    int i;
    for(i=0;i<senses.size();i++)
    {
      ArrayList<String> dwords=new ArrayList<String>();
      decision.setSense(i, 1.0/((double)(i+2)), dwords);
     
    }
    decision.calculateAnswer();
    return decision;
  }
View Full Code Here

  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;
  }
View Full Code Here

   @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++)
    {
      ArrayList<String> dwords=new ArrayList<String>();
      double w=0.0;
      for(AmbiguousWord winWord:window)
      {
        if(winWord.getSenses().size()>0)
        {
          for(Sense s:winWord.getSenses())
          {
            w+=this.scoring.calculateOverlap(senses.get(i).getBagOfWords(), s.getSynonyms(), 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;
  }
View Full Code Here

      for(SkipFilter skip:this.skipFilters)
        ban=ban&&skip.shouldITry(targetWord);
      if(targetWord.getSenses().size()>0)
      {
        ArrayList<AmbiguousWord> window= this.getWindow(target, document);       
        Decision d=new Decision(targetWord,window);
        d.calculateAnswer();
        if(ban)
        {
          d=this.disambiguate(targetWord, window);
          String t="true";
          if(t.equals(this.getValue("asFilter")))
          {
            for(int x=0;x<d.getSenseCount();x++)
            {
              if(d.getWeights()[x]>0.0)
              {
                d.getWeights()[x]=1.0;
              }
            }
            d.calculateAnswer();
          }
         
          if(d.isAttempted())
          {
            if(t.equals(this.getValue("asVoting")))
            {
              Decision d2=tie.disambiguate(targetWord, window);
              //normalize the weigths
              d.normalizeWeigths();
              if(d2.isAttempted())
              {
                d2.normalizeWeigths();
                for(int x=0;x<d.getSenseCount();x++)
                  d.getWeights()[x]+=d2.getWeights()[x];
                d.calculateAnswer();
              }
            } 
            else
            {
View Full Code Here

TOP

Related Classes of gannuWSD.testing.Decision

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.