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

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


      for (int i = 0; i < tokens.size(); i++) {
        BaseToken token = tokens.get(i);

        // Determine HeadId
        DepNode node = new DepNode();
        ConllDependencyNode casDepNode = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, token).get(0);
        casDepNode.getDeprel();
        String headRelation = casDepNode.getDeprel();
        ConllDependencyNode head = casDepNode.getHead();
       
        // If there is no head, this is the head node, set node to 0
        int headId = (head == null) ? 0 : depNodeToID.get(head);

        // Populate Dependency Node / Tree information
View Full Code Here


                tokens.add((BaseToken) tokenIterator.next());
            }
            //logger.info(" new sentence: ");
            FSIterator nodeIterator = nodeIndex.subiterator(sentence);
            while (nodeIterator.hasNext()) {
                ConllDependencyNode node = (ConllDependencyNode) nodeIterator.next();
                if (node.getId()!=0) {
                    nodes.add(node);
                }
                //logger.info(node.getFORM()+" ");
            }

           
           
            ListIterator<BaseToken>           itt = tokens.listIterator();
            ListIterator<ConllDependencyNode> itn = nodes.listIterator();
            BaseToken           bt = null;
            ConllDependencyNode dn = null;
            if (tokens.size()>0 && nodes.size()>0) {
                // iterate through the parallel sorted lists
                if (itt.hasNext()) bt                  = itt.next();
                if (itn.hasNext()) dn                  = itn.next();
                if (dn != null)
                    if (dn.getId()==0 && itn.hasNext())
                        dn = itn.next();
                while (itt.hasNext() || itn.hasNext()) {
                    if (bt.getBegin()==dn.getBegin() ) { // Allow ragged right edge //&& bt.getEnd()==dn.getEnd()) {
                        dn.setLemma( bt.getNormalizedForm() );
                        if (dn.getLemma()==null)
                            dn.setLemma( dn.getForm().toLowerCase() );
                        dn.addToIndexes();
                        if (itt.hasNext()) bt = itt.next();
                        if (itn.hasNext()) dn = itn.next();
                    } else if ( bt.getBegin()<dn.getBegin() ) {
                        if (itt.hasNext()) bt = itt.next(); else break;
                    } else if ( bt.getBegin()>dn.getBegin() ) {
                        // not every node will get a lemma b/c not all tokens are word tokens
                        if (itn.hasNext()) {
                            dn.setLemma( dn.getForm().toLowerCase() );
                            dn.addToIndexes();
                            dn = itn.next();
                        } else break;
                    }
                }
                if (bt.getBegin()==dn.getBegin() && bt.getEnd()==dn.getEnd()) {
                    dn.setLemma( bt.getNormalizedForm() );
                    dn.addToIndexes();
                }
            }
           
    }
       
View Full Code Here

    return nodes.length;   
  }

  private ConllDependencyNode getDepLCA(ConllDependencyNode c1, ConllDependencyNode c2) {
    HashSet<Annotation> ancestors = new HashSet<Annotation>();
    ConllDependencyNode temp = null;
    temp = c2.getHead();
    while(temp != null){
      ancestors.add(temp);
      temp = temp.getHead();
    }
    temp = c1.getHead();
    while(temp != null){
      if(ancestors.contains(temp)){
        break;
      }
      temp = temp.getHead();
    }
    return temp;
  }
View Full Code Here

      }else{
        StringBuffer buf = new StringBuffer();

        // first go up from the anaphor to the Lowest common ancestor... (LCA)
        buf.append(c2.getDeprel());
        ConllDependencyNode cur = c2.getHead();
        while(cur != depLca && cur != null){
          String rel = cur.getDeprel();
          if(rel == null){
            cur = null;
            break;
          }
          buf.append("<");
          buf.append(cur.getDeprel());
          cur = cur.getHead();
        }

        // add a "discourse node" if the relation goes between sentences.
        if(cur == null) buf.append("<TOP");

        // now up from the antecedent to the LCA
        StringBuffer bwd = new StringBuffer();
        bwd.append(c1.getDeprel());
        bwd.insert(0, ">");
        cur = c1.getHead();
        while(cur != depLca && cur != null){
          String rel = cur.getDeprel();
          if(rel == null){
            cur = null;
            break;
          }
          bwd.insert(0,cur.getDeprel());
          bwd.insert(0,">");
          cur = cur.getHead();
        }

        buf.append(bwd);
        depPath = buf.toString();
        initNGrams(ngrams, depPath, 3);
View Full Code Here

  public static ConllDependencyNode getDependencyNode(JCas jCas, Annotation annot) {

    AnnotationIndex nodeIndex = jCas.getAnnotationIndex(ConllDependencyNode.type);
      FSIterator nodeIterator = nodeIndex.iterator();
      while (nodeIterator.hasNext()) {
          ConllDependencyNode node = (ConllDependencyNode) nodeIterator.next();
          if (equalCoverage(annot,node)) {
            return node;
          }
      }
      return null;
View Full Code Here

  public static List<ConllDependencyNode> getDependencyNodes(JCas jCas, Annotation annot) {
    ArrayList<ConllDependencyNode> output = new ArrayList<ConllDependencyNode>();
    AnnotationIndex nodeIndex = jCas.getAnnotationIndex(ConllDependencyNode.type);
      FSIterator nodeIterator = nodeIndex.iterator();
      while (nodeIterator.hasNext()) {
          ConllDependencyNode node = (ConllDependencyNode) nodeIterator.next();
          if (doesSubsume(annot,node)) {
            output.add(node);
          }
      }
      return output;
View Full Code Here

    pathLtoR.clear();
    boolean foundMatch = false;
    for (int i=0; i<pathUp1.size(); i++ ) {
     
      // Assemble the part of the path from node1 to common ancestor
      ConllDependencyNode nodeUp1 = pathUp1.get(i);
      pathLtoR.add(nodeUp1);

      // Check each node above node2 for a match
      pathRtoL.clear();
      for (int j=0; j<pathUp2.size(); j++ ) {
        ConllDependencyNode nodeUp2 = pathUp2.get(j);       
        if (DependencyUtility.equalCoverage(nodeUp1, nodeUp2)) {
          // word-rel<word-rel<commonparent>rel-word>rel-word
          pathLtoR.setCommonNode(nodeUp1);
         
          // add the two halves of the path together
View Full Code Here

    return pathUp1;
  }

  public static List<ConllDependencyNode> getRightSibs( ConllDependencyNode refNode, List<ConllDependencyNode> tree ) {
   
    ConllDependencyNode parent = refNode.getHead();
    List<ConllDependencyNode> out = new ArrayList<ConllDependencyNode>();
   
    for ( ConllDependencyNode node : tree.subList( tree.indexOf(refNode)+1, tree.size() ) ) {
      if ( node.getHead().equals(parent) ) {
        out.add(node);
View Full Code Here

    return out;
  }
 
  public static List<ConllDependencyNode> getLeftSibs( ConllDependencyNode refNode, List<ConllDependencyNode> tree ) {
   
    ConllDependencyNode parent = refNode.getHead();
    List<ConllDependencyNode> out = new ArrayList<ConllDependencyNode>();
   
    List<ConllDependencyNode> lSide = tree.subList(0,tree.indexOf(refNode));
    for ( int i=tree.indexOf(refNode)-1; i>=0; i-- ) {
      ConllDependencyNode node = lSide.get(i);
      if ( node.getHead().equals(parent) ) {
        out.add(node);
      }
    }
    return out;
  }
View Full Code Here

      if ( node.equals(refNode) ) {
        out.add(node);
      } else {
       
        // Anything with refNode on its path to root is progeny.  Requires acyclicity
        ConllDependencyNode upNode = node;
        while (upNode.getHead()!=null) {
          upNode = upNode.getHead();
          if (upNode.equals(refNode)) {
            out.add(node);
            break;
          }
        }
       
View Full Code Here

TOP

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

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.