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

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


  public DependencyPath reverse() {
    DependencyPath current = this;
    DependencyPath newPath = new DependencyPath();
    for (int i=current.size()-1; i>=0; i--) {
      ConllDependencyNode tip = current.get(i);
      newPath.add( tip );
      if (isCommonNode(tip)) {
        newPath.setCommonNode(tip);
      }
    }
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.getHead().id));
            uimaNode.setDeprel(clearNode.getLabel());
            uimaNode.setPhead(null);
            uimaNode.setPdeprel("_");

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

    }
   
   
    List<ConllDependencyNode> depnodes = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, arg);
    if (!depnodes.isEmpty()) {
      ConllDependencyNode depnode = DependencyUtility.getNominalHeadNode(depnodes);

      // 1) check if the head node of the entity mention is really just part of a larger noun phrase
      if (depnode.getDeprel().matches("(NMOD|amod|nmod|det|predet|nn|poss|possessive|infmod|partmod|rcmod)")) {
        vfeat.put(POSTCOORD_NMOD, true);
      }

      // 4) search dependency paths for discussion context
      for (ConllDependencyNode dn : DependencyUtility.getPathToTop(jCas, depnode)) {
View Full Code Here

        BaseToken token = tokens.get(i);

        // Determine HeadId
        List<ConllDependencyNode> casDepNodes = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, token);
       
        ConllDependencyNode casDepNode = casDepNodes.get(0);
        if(casDepNode.getId() == 0) casDepNode = casDepNodes.get(1);

        deprels[i] = casDepNode.getDeprel();
        ConllDependencyNode head = casDepNode.getHead();

        // If there is no head, this is the head node, set node to 0
        headIDs[i] = (head == null) ? 0 : depNodeToID.get(head);

        // Populate Dependency Node / Tree information
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

    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

    }
   
   
    List<ConllDependencyNode> depnodes = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, mention);
    if (!depnodes.isEmpty()) {
      ConllDependencyNode depnode = DependencyUtility.getNominalHeadNode(depnodes);

      // 1) check if the head node of the entity mention is really just part of a larger noun phrase
      if (depnode.getDeprel().matches("(NMOD|amod|nmod|det|predet|nn|poss|possessive|infmod|partmod|rcmod)")) {
        vfeat.put(POSTCOORD_NMOD, true);
      }

      // 4) search dependency paths for discussion context
      for (ConllDependencyNode dn : DependencyUtility.getPathToTop(jCas, depnode)) {
View Full Code Here

   
    // search dependency paths for stuff
    List<ConllDependencyNode> depnodes = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, mention);
    if (!depnodes.isEmpty()) {
      ConllDependencyNode depnode = DependencyUtility.getNominalHeadNode(depnodes);
      for (ConllDependencyNode dn : DependencyUtility.getPathToTop(jCas, depnode)) {
        if ( isDonorTerm(dn) ) {
          vfeat.put(DONOR_DEPPATH, true);
        }
        if ( isFamilyTerm(dn) ) {
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.