예제 #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;
  }
예제 #2
0
  public void projectivize() {
    IntArrayList ids = new IntArrayList();
    int i, size = size();
    DEPNode nonProj;

    for (i = 1; i < size; i++) ids.add(i);

    while ((nonProj = getSmallestNonProjectiveArc(ids)) != null)
      nonProj.setHead(nonProj.getHead().getHead(), DEPLib.DEP_NON_PROJ);
  }
예제 #3
0
  public void resetHeads(StringIntPair[] heads) {
    int i, size = size(), len = heads.length;
    StringIntPair head;
    DEPNode node;

    for (i = 1; i < len && i < size; i++) {
      node = get(i);
      head = heads[i];

      if (head.i == DEPLib.NULL_ID) node.clearHead();
      else node.setHead(get(head.i), head.s);
    }

    for (i = len; i < size; i++) get(i).clearHead();
  }
예제 #4
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;
  }