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

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


      if ( refNodes.contains(node) ) {
        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 (refNodes.contains(upNode)) {
            out.add(node);
            break;
          }
View Full Code Here



  public static String dumpDependencyGraph(Annotation annotation) {
    StringBuilder builder = new StringBuilder();
    for (ConllDependencyNode depNode : JCasUtil.selectCovered(ConllDependencyNode.class, annotation)) {
      ConllDependencyNode head = depNode.getHead();
      String headStr = (head != null) ? head.getCoveredText() : "TOP";
      builder.append(String.format("%s(%s, %s)\n", depNode.getDeprel(), depNode.getCoveredText(), headStr));
    }
    return builder.toString();
  }
View Full Code Here

                tokens.add((BaseToken) tokenIterator.next());
            }

            FSIterator nodeIterator = nodeIndex.subiterator(sentence);
            while (nodeIterator.hasNext()) {
                ConllDependencyNode node = (ConllDependencyNode) nodeIterator.next();
                if (node.getId()!=0) {
                    nodes.add(node);
                }
            }

            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() && bt.getEnd()==dn.getEnd()) {
                  dn.setPostag( bt.getPartOfSpeech() );
                  dn.setCpostag( bt.getPartOfSpeech() )
                  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() ) {
                  if (itn.hasNext()) dn = itn.next(); else break;
                }
              }
              if (bt.getBegin()==dn.getBegin() && bt.getEnd()==dn.getEnd()) {
                dn.setPostag( bt.getPartOfSpeech() );
                dn.setCpostag( bt.getPartOfSpeech() )
                dn.addToIndexes();
              }
            }
             
    }
       
View Full Code Here

        ArrayList<ConllDependencyNode> uimaNodes = new ArrayList<ConllDependencyNode>(tokens.size()+1);
       
        // Create the root node first
        int rootBegin = tokens.get(0).getBegin();
        int rootEnd = tokens.get(tokens.size()-1).getEnd();
        uimaNodes.add( 0, new ConllDependencyNode(jcas, rootBegin, rootEnd));

        // Create all the other nodes
        for (int i=1; i<clearTree.size(); i++) {
            int nodeBegin = tokens.get(i-1).getBegin(); // assumes that tokens are off 1 from clearTree
            int nodeEnd = tokens.get(i-1).getEnd();
            ConllDependencyNode uimaNode = new ConllDependencyNode(jcas, nodeBegin, nodeEnd);
            uimaNodes.add(i,uimaNode);
        }
       
        // Set values in all the other nodes
        for (int i=1; i<clearTree.size(); i++) {
           

            DepNode clearNode = clearTree.get(i);
            ConllDependencyNode uimaNode = uimaNodes.get(i);

            uimaNode.setId(clearNode.id);
            uimaNode.setForm(clearNode.form);
            uimaNode.setLemma(clearNode.lemma);
            uimaNode.setCpostag(clearNode.pos);
            uimaNode.setPostag(clearNode.pos);
            uimaNode.setFeats("_");
            uimaNode.setHead(uimaNodes.get(clearNode.headId));
            uimaNode.setDeprel(clearNode.deprel);
            uimaNode.setPhead(null);
            uimaNode.setPdeprel("_");

            
       }
       
        return uimaNodes;//uimaNodes.get(0); //return the root node
View Full Code Here

  public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1,
      IdentifiedAnnotation arg2) throws AnalysisEngineProcessException {

    List<Feature> features = new ArrayList<Feature>();

    ConllDependencyNode node1 = DependencyParseUtils.findAnnotationHead(jCas, arg1);
    ConllDependencyNode node2 = DependencyParseUtils.findAnnotationHead(jCas, arg2);
    if (node1 == null || node2 == null)
    {
      return features;
    }
View Full Code Here

    return getTokenRelTreeString(jCas, nodes, annotations, labels, false);
  }
 
  public static String getTokenRelTreeString(JCas jCas, List<ConllDependencyNode> nodes, Annotation[] annotations, String[] labels, boolean getParent){
    Map<ConllDependencyNode, SimpleTree> node2tree = new HashMap<ConllDependencyNode, SimpleTree>();
    ConllDependencyNode topNode = null;
   
    // create a SimpleTree object that corresponds to this dependency tree, where the
    // root is the head of the sentence and the children are all the words such that the parent
    // is their head. In this case every word is represented by its relationship as well as
    // its word
    for(ConllDependencyNode node : nodes){
      if(node.getHead() == null){
        topNode = node;
        continue;
        // do absolutely nothing with this -- it covers the whole sentence and has no useful info
//        continue;
//      }else if(node.getHead().getHead() == null){
//        topNode = node;
      }
          
      SimpleTree curTree = null;
      SimpleTree headTree = null;
      if(!node2tree.containsKey(node)){
        curTree = SimpleTree.fromString(String.format("(%s %s)", node.getDeprel(), node.getCoveredText()));
        node2tree.put(node, curTree);
      }else{
        curTree = node2tree.get(node);
      }


      if(curTree.parent == null && node.getHead() != null){
        if(node2tree.containsKey(node.getHead())){
          headTree = node2tree.get(node.getHead());
        }else{
          String token = node.getHead().getHead() == null ? "TOP" : node.getHead().getCoveredText();
          headTree = SimpleTree.fromString(String.format("(%s %s)", node.getHead().getDeprel(), SimpleTree.escapeCat(token)));
          node2tree.put(node.getHead(), headTree);
        }

        curTree.parent = headTree.children.get(0);
        headTree.children.get(0).addChild(curTree);
      }
    }
   
    ConllDependencyNode highestHead = null;
    ConllDependencyNode leftmostHead = null;
    ConllDependencyNode rightmostHead = null;
    List<SimpleTree> annotationNodes = Lists.newArrayList();
   
    // take the set of input annotations and the corresponding labels and insert them into the SimpleTree
    for(int i = 0; i < annotations.length; i++){
      // get the node representing the head of this annotation
      List<ConllDependencyNode> coveredNodes = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, annotations[i]);
      if(coveredNodes == null || coveredNodes.size() == 0) continue;
      ConllDependencyNode headNode = DependencyUtility.getNominalHeadNode(coveredNodes);
     
      // is this the highest node of all the annotations we're looking at?
      if(highestHead == null || (distanceFromRoot(headNode) < distanceFromRoot(highestHead))){
        highestHead = headNode;
      }
      if(leftmostHead == null || headNode.getBegin() < leftmostHead.getBegin()){
        leftmostHead = headNode;
      }
      if(rightmostHead == null || headNode.getEnd() > rightmostHead.getEnd()){
        rightmostHead = headNode;
      }
     
      SimpleTree insertionPoint = node2tree.get(headNode);
      SimpleTree insertingTree = new SimpleTree(insertionPoint.cat);
View Full Code Here

    return node;
  }
 
  public static String getTokenTreeString(JCas jCas, List<ConllDependencyNode> nodes, Annotation[] annotations, String[] labels, boolean getParent){
    Map<ConllDependencyNode, SimpleTree> node2tree = getNodeTreeMap(nodes);
    ConllDependencyNode topNode = getTopNode(nodes);
   
    ConllDependencyNode highestHead = null;
    ConllDependencyNode leftmostHead = null;
    ConllDependencyNode rightmostHead = null;
    List<SimpleTree> annotationNodes = Lists.newArrayList();
    // take the set of input annotations and the corresponding labels and insert them into the SimpleTree
    for(int i = 0; i < annotations.length; i++){
      // get the node representing the head of this annotation
      List<ConllDependencyNode> coveredNodes = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, annotations[i]);
      if(coveredNodes == null || coveredNodes.size() == 0) continue;
      ConllDependencyNode headNode = DependencyUtility.getNominalHeadNode(coveredNodes);
     
      // is this the highest node of all the annotations we're looking at?
      if(highestHead == null || (distanceFromRoot(headNode) < distanceFromRoot(highestHead))){
        highestHead = headNode;
      }
      if(leftmostHead == null || headNode.getBegin() < leftmostHead.getBegin()){
        leftmostHead = headNode;
      }
      if(rightmostHead == null || headNode.getEnd() > rightmostHead.getEnd()){
        rightmostHead = headNode;
      }
     
      SimpleTree insertionPoint = node2tree.get(headNode);
      SimpleTree insertingTree = new SimpleTree(insertionPoint.cat);
View Full Code Here

    pet = lowestAncestor;
    return pet;
  }
 
  private static ConllDependencyNode getTopNode(List<ConllDependencyNode> nodes){
    ConllDependencyNode topNode = null;
    for(ConllDependencyNode node : nodes){
      if(node.getHead() == null){
        topNode = node;
        break;
      }
View Full Code Here

    List<LinkedList<ConllDependencyNode>> paths = new ArrayList<LinkedList<ConllDependencyNode>>(2);
    LinkedList<ConllDependencyNode> node1ToHeadPath = DependencyParseUtils.getPathToSentenceHead(node1);
    LinkedList<ConllDependencyNode> node2ToHeadPath = DependencyParseUtils.getPathToSentenceHead(node2);

    // We will remove the last item in each path until they diverge
    ConllDependencyNode ancestor = null;
    while (!node1ToHeadPath.isEmpty() && !node2ToHeadPath.isEmpty()) {
      if (node1ToHeadPath.getLast() == node2ToHeadPath.getLast()) {
        node1ToHeadPath.removeLast();
        ancestor = node2ToHeadPath.removeLast();
      } else {
View Full Code Here

   */
  public static ConllDependencyNode findAnnotationHead(JCas jcas, Annotation annotation) {

    for (ConllDependencyNode depNode : JCasUtil.selectCovered(jcas, ConllDependencyNode.class, annotation)) {

      ConllDependencyNode head = depNode.getHead();
      if (head == null || head.getHead()==null||head.getEnd() <= annotation.getBegin() || head.getBegin() > annotation.getEnd()) {
        // The head is outside the bounds of the annotation, so this node must be the annotation's head
        return depNode;
      }
    }

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.