Examples of TreebankNode


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

    SimpleTree t = new SimpleTree(lca.getNodeType());
    if(lca instanceof TerminalTreebankNode){
      t.addChild(new SimpleTree(lca.getNodeValue()));
    }else{
      for(int i = 0; i < lca.getChildren().size(); i++){
        TreebankNode tn = lca.getChildren(i);
        if(tn.getEnd() > t1.getBegin() && tn.getBegin() < t2.getEnd()){
          t.addChild(buildSimpleClonePET(lca.getChildren(i), t1, t2));
        }
      }
    }
    return t;
View Full Code Here

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

    return t;
  }
 
  // Find the least common ancestor of two other nodes, or null (top node) if they are in different sentences
  public static TreebankNode getLCA(TreebankNode t1, TreebankNode t2){
    TreebankNode temp = null;
    if(t2.getBegin() < t1.getBegin()){
      temp = t1;
      t1 = t2;
      t2 = temp;
    }
   
    TreebankNode lca = t2;
    while(lca != null && (lca.getBegin() > t1.getBegin() || lca.getEnd() < t1.getEnd())){
      lca = lca.getParent();
    }
    return lca;
  }
View Full Code Here

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

    // first get the root and print it out...
    TopTreebankNode root = AnnotationTreeUtils.getTreeCopy(jcas, AnnotationTreeUtils.getAnnotationTree(jcas, arg1));
   
//    SimpleTree tempClone = TreeExtractor.getSimpleClone(root);
//    features.add(new Feature("TK_FULL", tempClone.toString()));
    TreebankNode t1 = AnnotationTreeUtils.insertAnnotationNode(jcas, root, arg1, "ARG1");
    TreebankNode t2 = AnnotationTreeUtils.insertAnnotationNode(jcas, root, arg2, "ARG2");

    SimpleTree tree = null;
    if(t1.getBegin() <= t2.getBegin() && t1.getEnd() >= t2.getEnd()){
      // t1 encloses t2
      tree = TreeExtractor.getSimpleClone(t1);
    }else if(t2.getBegin() <= t1.getBegin() && t2.getEnd() >= t1.getEnd()){
      // t2 encloses t1
      tree = TreeExtractor.getSimpleClone(t2);
    }else{
      tree = TreeExtractor.extractPathEnclosedTree(t1, t2, jcas);
    }
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

      IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
    List<Feature> features = new ArrayList<Feature>();
    // first get the root and print it out...
    TopTreebankNode root = AnnotationTreeUtils.getTreeCopy(jcas, AnnotationTreeUtils.getAnnotationTree(jcas, arg1));
//    SimpleTree tempClone = TreeExtractor.getSimpleClone(root);
    TreebankNode t1 = AnnotationTreeUtils.insertAnnotationNode(jcas, root, arg1, "ARG1");
    TreebankNode t2 = AnnotationTreeUtils.insertAnnotationNode(jcas, root, arg2, "ARG2");

    SimpleTree tree = null;
    if(t1.getBegin() <= t2.getBegin() && t1.getEnd() >= t2.getEnd()){
      // t1 encloses t2
      tree = TreeExtractor.getSimpleClone(t1);
    }else if(t2.getBegin() <= t1.getBegin() && t2.getEnd() >= t1.getEnd()){
      // t2 encloses t1
      tree = TreeExtractor.getSimpleClone(t2);
    }else{
      tree = TreeExtractor.extractPathEnclosedTree(t1, t2, jcas);
    }
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{
      TerminalTreebankNode termNode = MarkableTreeUtils.getHead(node);
      String pos = termNode.getNodeType();
      if(pos.equals("NN") || pos.equals("NNP")) return "S";
View Full Code Here

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

import org.apache.ctakes.coreference.type.Markable;

public class MarkableTreeUtils {

  public static TreebankNode markableNode(JCas jcas, int a, int b){
    TreebankNode lowestDom = null;
    int overage = Integer.MAX_VALUE;
    FSIterator<Annotation> iter = jcas.getJFSIndexRepository().getAnnotationIndex(TreebankNode.type).iterator();
    while(iter.hasNext()){
      TreebankNode node = (TreebankNode) iter.next();
      if(node.getBegin() == a && node.getEnd() == b){
        // this code will drill down -- actually want to go other way
//        while(node.getChildren() != null && node.getChildren().size() == 1){
//          node = node.getChildren(0);
//        }
       
        // this code will head up as long as parent has the same span
        try{
          while(node.getParent() != null && node.getParent().getChildren().size() == 1 && !node.getParent().getNodeType().equals("TOP")){
            node = node.getParent();
          }
        }catch(NullPointerException e){
          System.err.println("Null pointer exception in AttributeCalculator::markableNode()");
        }
        return node;
      }else if(node.getBegin() <= a && node.getEnd() >= b){
        int tempOver = (a-node.getBegin()) + (node.getEnd()-b);
        if(tempOver < overage){
          lowestDom = node;
          overage = tempOver;
        }
      }
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.