Package gannuWSD.algorithms

Source Code of gannuWSD.algorithms.GraphWNBased

package gannuWSD.algorithms;

import gannuNLP.data.AmbiguousWord;
import gannuNLP.data.Input;
import gannuNLP.data.Sense;
import gannuWSD.graphs.Graph;
import gannuWSD.graphs.GraphHandler;
import gannuWSD.graphs.GraphNode;
import gannuWSD.testing.Decision;

import java.util.ArrayList;

/**
* Under construction please do not use.
* @author Francisco Viveros-Jiménez
*
*/
public class GraphWNBased extends WSDAlgorithm{
  int deep;
  GraphHandler graphs;
  ArrayList<Graph> cache;
  AmbiguousWord lastWord;
    public GraphWNBased()
    {
      super();
      this.name="GraphWNBased";
      this.cache=new ArrayList<Graph>();
      this.lastWord=null;
      this.graphs=null;
    }
  @Override
  public void init(Input document) throws Exception {
    if(document!=null)
      System.out.println("\nDisambiguating "+document.toString());
    if(this.getValue("deep")==null)
    {
      deep=4;
    }
    else
    {
      deep=Integer.parseInt(this.getValue("deep"));
    }
        if(this.graphs==null)
          this.graphs=new GraphHandler(this.dict);
  }

  @Override
  public Decision disambiguate(AmbiguousWord target,
      ArrayList<AmbiguousWord> window) throws Exception {
    System.out.print(".");
    Decision d=new Decision(target,window);
    //System.out.print(target.getIndex());
    ArrayList<String> rels=new ArrayList<String>(1);
    rels.add("all");
    for(int i=0;i<target.getSenses().size();i++)
    {
      Sense sense=target.getSenses().get(i);
      ArrayList<String>dwords=new ArrayList<String>();
      Graph g=this.graphs.loadGraph(sense, dict);
      double w=0.0;
      for(AmbiguousWord word:window)
      {
        for(Sense s:word.getSenses())
        {
          GraphNode gn=g.get(s, deep, "all");
          if(gn!=null)
          {       
            dwords.add(word.getLemma());
            break;
          }
        }
      }
        w=g.getRootDegree(window,deep,rels);
      d.setSense(i, w, dwords);
    }
   
    d.calculateAnswer();
    return d;
  }
  @Override
  public boolean IsUseful(AmbiguousWord target, AmbiguousWord windowWord)
      throws Exception {   
    if(!target.equals(this.lastWord))
    {
      this.lastWord=target;
      this.cache.clear();
      for(Sense sense:target.getSenses())
      {
        this.cache.add(this.graphs.loadGraph(sense, dict));
      }
    }
    for(Graph g:this.cache)
    {     
      for(Sense s:windowWord.getSenses())
      {
          GraphNode gn=g.get(s, deep, "all");
          if(gn!=null)
          {       
            return true;
          }
      }
     
    }       
    return false;
  }

}
TOP

Related Classes of gannuWSD.algorithms.GraphWNBased

TOP
Copyright © 2018 www.massapi.com. 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.