Examples of TreebankNode


Examples of org.apache.ctakes.typesystem.type.syntax.TreebankNode

  public static LinkedList<TreebankNode> bfs(Queue<TreebankNode> q, TreebankNode X, TreebankNode node){
    // now traverse the queue until it is empty, adding NPs
    LinkedList<TreebankNode> list = new LinkedList<TreebankNode>();
    HashSet<TreebankNode> path = new HashSet<TreebankNode>();
    TreebankNode cur = node;
    if(cur != null){
      path.add(cur);
      while(cur != X){
        cur = cur.getParent();
        path.add(cur);
      }
    }
    while(!q.isEmpty()){
      cur = q.remove();
      if(cur.getNodeType().equals("NP") && !path.contains(cur)){
        list.add(cur);
        // I think:
        // if cur is on the path then short circuit.
      }
      for(int i = 0; i < cur.getChildren().size(); i++){
        TreebankNode n = cur.getChildren(i);
        if(n == node) break;
        if(!(n instanceof TerminalTreebankNode)){
          q.add(cur.getChildren(i));
        }
        if(path.contains(n)) break;
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.syntax.TreebankNode

 
  // find the next "X" in Hobbs algorithm.  "Y" is the child of X on the path up to X that we took.
  // it is needed because the search is constrained to only the children of new X to the left of the
  // path from whence we came.
  public static TreebankNode nextX(TreebankNode curX){
    TreebankNode nextX = curX.getParent();
//    Y = curX;
    while(!(nextX.getNodeType().equals("NP") || nextX.getNodeType().equals("S"))){
//      Y = nextX;
      nextX = nextX.getParent();
      if(nextX == null) break;
    }
    return nextX;
  }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.syntax.TreebankNode

    while(Y.getParent() != X){
      Y = Y.getParent();
    }
   
    for(int i = 0; i < X.getChildren().size(); i++){
      TreebankNode n = X.getChildren(i);
      q.add(n);
      if(n == Y) break;
    }
    return q;
  }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.syntax.TreebankNode

    // initialize the mapping of nodes to markables, as well as the set of all markables so we know
    // how many of them we've found
    for(Annotation a : lm){
      if(a.getBegin() > m.getBegin()) break;
//      if(sentDist(jcas,m,(Markable)a) > 3) continue;
      TreebankNode n = MarkableTreeUtils.markableNode(jcas, a.getBegin(), a.getEnd());
      node2mark.put(n, (Markable)a);
      allMarks.add((Markable)a);
    }
   
    // find out what sentence we're at to make it easier to go backwards:
    for(int i = 0; i < sentList.size(); i++){
      Annotation a = sentList.get(i);
      if(m.getBegin() >= a.getBegin() && m.getEnd() <= a.getEnd()){
        sentInd = i;
        break;
      }
    }
   
    TreebankNode node = MarkableTreeUtils.markableNode(jcas, m.getBegin(), m.getEnd());
    TreebankNode Y = node;
    TreebankNode X = HobbsTreeNavigator.nextX(node);
     
    if(X != null){
      // Step 3: Traverse left side of X
      // First add the children to the left to the queue
//      Queue<TreebankNode> q = new LinkedList<TreebankNode>();
      Queue<TreebankNode> q = HobbsTreeNavigator.initializeQueue(X, Y);
      LinkedList<TreebankNode> tempList = HobbsTreeNavigator.bfs(q, X, Y);
      // before adding to actual queue (ll), need to make sure each of these has an NP node between it and X
      for(TreebankNode cur : tempList){
        TreebankNode n = cur.getParent();
        while(n != null && n != X){
          if(n.getNodeType().equals("NP") || n.getNodeType().equals("S")){
            if(node2mark.containsKey(n)){
              ll.add(node2mark.get(n));
              allMarks.remove(node2mark.get(n));
              break;
            }
          }
          n = n.getParent();
        }
      }
     
      if(allMarks.size() == 0) return ll;
     
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.syntax.TreebankNode

        path = "";
      }else{
        // First make our way up from the antecedent (node 2), stopping when we hit the LCA or
        // the node labeled TOP (the LCA of all trees in the absence of a discourse model)
        StringBuffer buf = new StringBuffer();
        TreebankNode cur = n2.getParent();
        //        if(n2 instanceof TerminalTreebankNode) cur = cur.getParent();

        while(cur != lca && !(cur instanceof TopTreebankNode)){
          buf.append(cur.getNodeType());
          buf.append("<");
          if(cur.getParent() != null){
            cur = cur.getParent();
          }else{
            break;
          }
        }
        buf.append(lca==null?"TOP":lca.getNodeType());

        StringBuffer bwd = new StringBuffer();
        //      if(lca == null) cur = n1.getRoot();
        cur = n1.getParent();
        //        if(n1 instanceof TerminalTreebankNode) cur = cur.getParent();
        while(cur != lca && !(cur instanceof TopTreebankNode)){
          bwd.insert(0,cur.getNodeType());
          bwd.insert(0,">");
          cur = cur.getParent();
        }
        buf.append(bwd);
        path = buf.toString();
        initNGrams(ngrams, path,3);
        initNGrams(ngrams, path,4);
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.syntax.TreebankNode

  static boolean isDefinite (String s) {
    return s.toLowerCase().startsWith("the ");
  }

  public String number (Markable m){
    TreebankNode node = MarkableTreeUtils.markableNode(jcas, m.getBegin(), m.getEnd());
    if(node == null) return basicNumber(m);
    try{
      TreebankNode wordNode = MarkableTreeUtils.getHead(node);
      TreebankNode posNode = wordNode.getParent();
      String pos = posNode.getNodeType();
      if(pos.equals("NN") || pos.equals("NNP")) return "S";
      else if(pos.equals("NNS") || pos.equals("NNPS")) return "P";
      else{
        // obviously there are many other pronouns but we don't cover personal pronouns and so
        // these are all we need.
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.syntax.TreebankNode

    pos = getPOS();
  }

  private String getPOS(){
    try{
      TreebankNode node = MarkableTreeUtils.markableNode(jcas, m.getBegin(), m.getEnd());
//      TerminalTreebankNode wordNode = (TerminalTreebankNode) node.getRoot().getTerminals().get(node.getHeadIndex());
      TerminalTreebankNode wordNode = MarkableTreeUtils.getHead(node);
      String pos = wordNode.getParent().getNodeType();
      return pos;
    }catch(Exception e){
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.syntax.TreebankNode

        }

        if(printTrees){
          //          Markable anaphor = vec.getAnaphor();
          //          Markable antecedent = vec.getAntecedent();
          TreebankNode antecedentNode = MarkableTreeUtils.markableNode(jcas, antecedent.getBegin(), antecedent.getEnd());
          TreebankNode anaphorNode = MarkableTreeUtils.markableNode(jcas, anaphor.getBegin(), anaphor.getEnd());
          debug.println(TreeUtils.tree2str(antecedentNode));
          debug.println(TreeUtils.tree2str(anaphorNode));
//          TopTreebankNode pathTree = TreeExtractor.extractPathTree(antecedentNode, anaphorNode, jcas);
          SimpleTree pathTree = TreeExtractor.extractPathTree(antecedentNode, anaphorNode);
          SimpleTree petTree = TreeExtractor.extractPathEnclosedTree(antecedentNode, anaphorNode, jcas);
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.syntax.TreebankNode

  private static boolean isPleonastic (TerminalTreebankNode ttn,
      HashSet<String> modalAdj, HashSet<String> cogved, HashSet<String> othervb) {
    if (!ttn.getCoveredText().equalsIgnoreCase("it")) return false;

    if (ttn.getParent().getNodeType().equals("PRP")) {
      TreebankNode tn = ttn.getParent().getParent();
      while (tn.getNodeType().startsWith("NP"))
        tn = tn.getParent();
      if (tn.getNodeType().equals("S")) {
        TreebankNode par = tn;
        TreebankNode vp = findP(tn, "VP", 0);
        while (vp!=null) vp = findP(par = vp, "VP", 0);
        vp = par;
        par = vp.getParent();

        FSArray c = vp.getChildren();
        TreebankNode firstChild = (TreebankNode) c.get(0);
        if (isBe(firstChild)) {
          TreebankNode adjP = findP(vp, "ADJP", 1);
          if (adjP!=null && modalAdj.contains(adjP.getCoveredText()) &&
              (findP(vp, "SBAR", 1)!=null ||
              findP(vp, "S", 1)!=null ||
              findP(adjP, "SBAR", 1)!=null ||
              findP(adjP, "S", 1)!=null))
            return true;
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.syntax.TreebankNode

  private static TreebankNode findP (TreebankNode n, String phraseTag, int startingChild) {
    FSArray c = n.getChildren();
    int i = startingChild;
    while (i < c.size()) {
      TreebankNode tn = (TreebankNode) c.get(i++);
      if (tn.getNodeType().equals(phraseTag) ||
          tn.getNodeType().startsWith(phraseTag+"-"))
        return tn;
    }
    return null;
  }
View Full Code Here
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.