Esempio n. 1
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;
  }
Esempio n. 2
0
  /** @param endIndex the ending index (exclusive). */
  public StringIntPair[] getHeads(int endIndex) {
    DEPArc head;
    int i;

    StringIntPair[] heads = new StringIntPair[endIndex];
    heads[0] = new StringIntPair(DEPLib.ROOT_TAG, DEPLib.NULL_ID);

    for (i = 1; i < endIndex; i++) {
      head = get(i).d_head;
      heads[i] =
          (head.node != null)
              ? new StringIntPair(head.label, head.getNode().id)
              : new StringIntPair(null, DEPLib.NULL_ID);
    }

    return heads;
  }
Esempio n. 3
0
  public List<List<DEPArc>> getArgumentList() {
    int i, size = size();
    List<DEPArc> args;
    DEPNode node;

    List<List<DEPArc>> list = new ArrayList<List<DEPArc>>();
    for (i = 0; i < size; i++) list.add(new ArrayList<DEPArc>());

    for (i = 1; i < size; i++) {
      node = get(i);

      for (DEPArc arc : node.getSHeads()) {
        args = list.get(arc.getNode().id);
        args.add(new DEPArc(node, arc.getLabel()));
      }
    }

    return list;
  }
Esempio n. 4
0
  @Deprecated
  public IntOpenHashSet getNonProjectiveSet() {
    IntObjectOpenHashMap<IntOpenHashSet> map = new IntObjectOpenHashMap<IntOpenHashSet>();
    int i, j, bIdx, eIdx, size = size();
    DEPNode curr, head, dep;

    for (i = 1; i < size; i++) {
      curr = get(i);
      head = curr.getHead();

      if (curr.id < head.id) {
        bIdx = curr.id;
        eIdx = head.id;
      } else {
        bIdx = head.id;
        eIdx = curr.id;
      }

      for (j = bIdx + 1; j < eIdx; j++) {
        curr = get(j);
        head = curr.getHead();

        if (head.id < bIdx || head.id > eIdx) {
          addNonProjectiveMap(map, i, j);
          addNonProjectiveMap(map, j, i);
        }

        for (DEPArc arc : curr.getDependents()) {
          dep = arc.getNode();

          if (dep.id < bIdx || dep.id > eIdx) {
            addNonProjectiveMap(map, i, dep.id);
            addNonProjectiveMap(map, dep.id, i);
          }
        }
      }
    }

    return getNonProjectiveMapAux(map);
  }