Package org.apache.ctakes.typesystem.type.syntax

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


    else return new MarkableProb(null,0.0);
  }
 
  private MarkableProb processDem(Markable anaphor, List<Markable> anteList, JCas jcas){
    double bestProb = 0.0;
    TreebankNode n = MarkableTreeUtils.markableNode(jcas, anaphor.getBegin(), anaphor.getEnd());
    TreebankNode parent = (n != null ? n.getParent() : null);
    TreebankNode gparent = (parent != null ? parent.getParent() : null);
    Markable ante = null;
    for(Markable antecedent: anteList){
      if(n!=null && parent != null && gparent != null && n.getNodeType().equals("WHNP") && parent.getNodeType().equals("SBAR")
          && gparent.getNodeType().equals("NP") && gparent.getChildren(1) == parent && gparent.getChildren(0).getNodeType().equals("NP")){
        TreebankNode anteNode = gparent.getChildren(0);
        Markable trueAnte = MarkableTreeUtils.nodeMarkable(jcas, anteNode.getBegin(), anteNode.getEnd());
        if(trueAnte == antecedent){
          bestProb = 1.0;
          ante = antecedent;
          break;
        }
View Full Code Here


  public static List<TreebankNode> getNodeList(TopTreebankNode tree){
    ArrayList<TreebankNode> list = new ArrayList<TreebankNode>();
    list.add(tree);
    int ind = 0
    while(ind < list.size()){
      TreebankNode cur = list.get(ind);
      for(int i = 0; i < cur.getChildren().size(); i++){
        list.add(cur.getChildren(i));
      }
      ind++;
    }
    return list;
  }
View Full Code Here

    }
      return getHighestIndexTerm(inTree.getChildren(inTree.getChildren().size()-1));
  }

  public static TopTreebankNode getTopNode(TreebankNode inTree) {
    TreebankNode cur = inTree;
    TopTreebankNode top = null;
   
    while(!(cur instanceof TopTreebankNode)){
      cur = cur.getParent();
    }
    top = (TopTreebankNode) cur;
    return top;
  }
View Full Code Here

        children.set(i,term);
        term.setParent(parent);
        term.addToIndexes();
      }else{
        try{
          TreebankNode child = new TreebankNode(jcas);
          child.setParent(parent);
          children.set(i, child);
          recursivelyCreateStructure(jcas, child, subtree, root);
          child.addToIndexes();
        }catch(NullPointerException e){
          System.err.println("MaxentParserWrapper Error: " + e);
          throw new AnalysisEngineProcessException();
        }
      }
View Full Code Here

    List<TerminalTreebankNode> terms = JCasUtil.selectCovered(TerminalTreebankNode.class, mention);
    if(terms == null || terms.size() == 0){
      return null;
    }
   
    TreebankNode coveringNode = AnnotationTreeUtils.annotationNode(jCas, mention);
    if(coveringNode == null) return terms.get(0);
   
    String pos =terms.get(0).getNodeType();
    // do not expand Verbs
    if(pos.startsWith("V")) return coveringNode;
   
    if(pos.startsWith("N")){
      // get first NP node:
      while(coveringNode != null && !coveringNode.getNodeType().equals("NP")){
        coveringNode = coveringNode.getParent();
      }
    }else if(pos.startsWith("J")){
      while(coveringNode != null && !coveringNode.getNodeType().equals("ADJP")){
        coveringNode = coveringNode.getParent();
      }
    }
    if(coveringNode == null) coveringNode = terms.get(0);
    return coveringNode;   
  }
View Full Code Here

      IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {
    List<Feature> features = new ArrayList<Feature>();
   
    SimpleTree tree = null;
    tree = new SimpleTree("BOP");
    TreebankNode lca = TreeExtractor.getLCA(AnnotationTreeUtils.annotationNode(jcas, arg1),
                        AnnotationTreeUtils.annotationNode(jcas, arg2));
       
    SimpleTree arg1Tree = new SimpleTree("ARG1");
    SimpleTree arg2Tree = new SimpleTree("ARG2");
   
View Full Code Here

//          TopTreebankNode t2 = AnnotationTreeUtils.getTreeCopy(AnnotationTreeUtils.getAnnotationTree(jcas, arg2));
         
          if(root == null){
            System.err.println("Root is null!");
          }
          TreebankNode t1 = AnnotationTreeUtils.insertAnnotationNode(jcas, root, arg1, "ARG1");
          TreebankNode t2 = AnnotationTreeUtils.insertAnnotationNode(jcas, root, arg2, "ARG2");
          String relationString = category + "(\"" + arg1.getCoveredText() + "\", \"" + arg2.getCoveredText() + "\")";
          rels.print("\t");
          rels.print(lineNum);
          rels.print("\t");
          rels.println(relationString);
          rels.flush();
          lineNum++;
//          root.setNodeType(category);
//          out.println(TreeExtractor.getSimpleClone(root));
//          out.flush();
         
         
          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

//    FSIterator<Annotation> iter = aJCas.getJFSIndexRepository().getAnnotationIndex(LookupWindowAnnotation.type).iterator();
    FSIterator<Annotation> iter = aJCas.getAnnotationIndex(TreebankNode.type).iterator();
    LinkedList<Annotation> l = FSIteratorToList.convert(iter);

    for (Annotation m : markables){
      TreebankNode node = MarkableTreeUtils.markableNode(aJCas, m.getBegin(), m.getEnd());
      if(node == null) continue;
      while(!(node.getNodeType().equals("NP") || node.getNodeType().equals("NML"))){
        node = node.getParent();
        if(node == null) break;
      }
      if(node == null) continue;
      if(node.getChildren().size() == 3 && node.getChildren(1).getNodeType().equals("CC")){
        continue;
      }
      // only expand if markable is at end of node.
      // the following expression is more complicated however due to the way that
      // NP sentences are annotated (and thus parsed).  The NP will technically include the period so we will allow the node an
      // extra character.  This should allow a period but nothing else.
      if(node.getEnd()-1 > m.getEnd()) continue;
      String s = node.getCoveredText().toLowerCase();
      if (s.startsWith("his ") ||
          s.startsWith("her ") ||
          s.startsWith("its "))
        m.setBegin(node.getBegin()+4);
      else if (s.startsWith("their "))
        m.setBegin(node.getBegin()+6);
      else if (!s.matches("^\\s*$"))          // some lookupwindows start w/ multiple linefeeds in the pitt data
        m.setBegin(node.getBegin());
    }
  }
View Full Code Here

    Map<Integer,TreebankNode> innerMap = null;
    // mark the boundaries of every NP:
    FSIterator<Annotation> nodeIter = jcas.getAnnotationIndex(TreebankNode.type).iterator();
    HashMap<Integer,Map<Integer,TreebankNode>> npMap = new HashMap<Integer,Map<Integer,TreebankNode>>();
    while(nodeIter.hasNext()){
      TreebankNode node = (TreebankNode) nodeIter.next();
      if(node.getNodeType().equals("NP")){
        innerMap = npMap.get(node.getBegin());
        if(innerMap == null){
          innerMap = new HashMap<Integer,TreebankNode>();
        }
        innerMap.put(node.getEnd(), node);
        npMap.put(node.getBegin(), innerMap);
      }
    }
   
    // now check if any of the NE markables share the exact same boundaries:
    FSIterator<Annotation> neIter = jcas.getAnnotationIndex(Markable.type).iterator();
    while(neIter.hasNext()){
      Markable nem = (Markable) neIter.next();
      innerMap = npMap.get(nem.getBegin());
      if(innerMap != null && innerMap.containsKey(nem.getEnd())){ 
        // found one!  Check if it has an NP parent and a PP sibling:
        TreebankNode node = innerMap.get(nem.getEnd());
        TreebankNode parent = node.getParent();
        if(parent.getChildren().size() == 2 && parent.getChildren(0) == node && parent.getNodeType().equals("NP") && parent.getChildren(1).getNodeType().equals("PP")){
          //   Jackpot!  Expand the original markable to be the whole NP -> NP PP construction.
          nem.setEnd(parent.getEnd());
        }
      }
    }
  }
View Full Code Here

  private void elevateAdjectives(JCas jcas){
    FSIterator<Annotation> markables = jcas.getAnnotationIndex(NEMarkable.type).iterator();
    while(markables.hasNext()){
      NEMarkable mark = (NEMarkable) markables.next();
      TreebankNode node = MarkableTreeUtils.markableNode(jcas, mark.getBegin(), mark.getEnd());
      if(node.getNodeType().equals("JJ")){
        while(node.getNodeType().equals("JJ")){
          node = node.getParent();
          if(node == null) break;
        }
        if(node != null){
          mark.setBegin(node.getBegin());
          mark.setEnd(node.getEnd());
        }
      }
    }
     
  }
View Full Code Here

TOP

Related Classes of org.apache.ctakes.typesystem.type.syntax.TreebankNode

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.