Exemple #1
0
  public static DEPTree buildFrom(IDEPTreeDatum treeDatum) {
    List<IDEPNodeDatum> nodeData = treeDatum.getDEPNodeData();
    DEPTree tree = new DEPTree();
    int i, size = nodeData.size();
    IDEPNodeDatum nd;
    DEPNode node;

    for (i = 0; i < size; i++) {
      nd = nodeData.get(i);
      tree.add(
          new DEPNode(
              nd.getID(),
              nd.getForm(),
              nd.getLemma(),
              nd.getPOS(),
              nd.getNamedEntity(),
              new DEPFeat(nd.getFeats())));
    }

    for (i = 0; i < size; i++) {
      nd = nodeData.get(i);
      node = tree.get(i + 1);

      node.initSHeads();
      node.setHead(new DEPArc(tree, nd.getSyntacticHead()));
      node.addSHeads(DEPLib.getSRLArcs(tree, nd.getSemanticHeads()));
    }

    tree.resetDependents();
    return tree;
  }
  private DEPTree getDEPTree(CTTree cTree) {
    DEPTree dTree = initDEPTree(cTree);
    addDEPHeads(dTree, cTree);

    if (dTree.containsCycle()) System.err.println("Error: cyclic dependencies exist");

    return dTree;
  }
Exemple #3
0
  public DEPTree clone() {
    IntObjectOpenHashMap<DEPNode> map = new IntObjectOpenHashMap<DEPNode>();
    DEPNode oNode, nNode, oHead, nHead;
    DEPTree tree = new DEPTree();
    int i, size = size();

    for (i = 1; i < size; i++) {
      oNode = get(i);
      nNode = new DEPNode(oNode);
      tree.add(nNode);
      nNode.id = i;
      map.put(oNode.id, nNode);

      if (oNode.x_heads != null) nNode.initXHeads();

      if (oNode.s_heads != null) nNode.initSHeads();
    }

    for (i = 1; i < size; i++) {
      oNode = get(i);
      nNode = tree.get(i);
      oHead = oNode.getHead();
      nHead = map.get(oHead.id);

      if (nHead == null) {
        nHead = tree.get(0);
      } else {
        if (oNode.x_heads != null) {
          for (DEPArc xHead : oNode.x_heads) {
            oHead = xHead.getNode();
            nNode.addXHead(map.get(oHead.id), xHead.getLabel());
          }
        }

        if (oNode.s_heads != null) {
          for (DEPArc sHead : oNode.s_heads) {
            oHead = sHead.getNode();
            nNode.addSHead(map.get(oHead.id), sHead.getLabel());
          }
        }
      }

      nNode.setHead(nHead, oNode.getLabel());
    }

    return tree;
  }
 private static Map<String, String> generatePOSTags(Question q) {
   ParseTree parse = new ParseTree();
   DEPTree tree = parse.process(q);
   // TODO this is horribly wrong, the same label CAN have different pos
   // tags
   Map<String, String> label2pos = Maps.newHashMap();
   Stack<DEPNode> stack = new Stack<DEPNode>();
   stack.push(tree.getFirstRoot());
   while (!stack.isEmpty()) {
     DEPNode tmp = stack.pop();
     label2pos.put(tmp.form, tmp.pos);
     for (DEPNode child : tmp.getDependentNodeList()) {
       stack.push(child);
     }
   }
   return label2pos;
 }
  /** Adds dependency heads. */
  private void addDEPHeads(DEPTree dTree, CTTree cTree) {
    int currId, headId, size = dTree.size(), rootCount = 0;
    DEPNode dNode;
    CTNode cNode;
    String label;

    for (currId = 1; currId < size; currId++) {
      dNode = dTree.get(currId);
      cNode = cTree.getToken(currId - 1);
      headId = cNode.c2d.d_head.getTokenId() + 1;

      if (currId == headId) // root
      {
        dNode.setHead(dTree.get(DEPLib.ROOT_ID), DEPLibKr.DEP_ROOT);
        rootCount++;
      } else {
        label = cNode.c2d.s_label;
        dNode.setHead(dTree.get(headId), label);
      }
    }

    if (rootCount > 1) System.err.println("Warning: multiple roots exist");
  }