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); }
public DEPNode getRightMostDependent(int id) { DEPNode node, head = get(id); int i; for (i = size() - 1; i > id; i--) { node = get(i); if (node.getHead() == head) return node; } return null; }
/** * Returns {@code true} if this tree contains a cycle. * * @return {@code true} if this tree contains a cycle. */ public boolean containsCycle() { int i, size = size(); DEPNode node; for (i = 1; i < size; i++) { node = get(i); if (node.getHead().isDescendentOf(node)) return true; } return false; }
public DEPNode getLeftMostDependent(int id) { DEPNode node, head = get(id); int i; for (i = 1; i < id; i++) { node = get(i); if (node.getHead() == head) return node; } return null; }
public DEPNode getFirstRoot() { DEPNode node, root = get(0); int i, size = size(); for (i = 1; i < size; i++) { node = get(i); if (node.getHead() == root) return node; } return null; }
@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); }
/** Resets dependents of each node in this tree. */ public void resetDependents() { int i, size = size(); DEPNode node, head; for (i = 0; i < size; i++) get(i).l_dependents = new ArrayList<DEPArc>(); for (i = 1; i < size; i++) { node = get(i); head = node.getHead(); if (head != null) head.addDependent(node, node.getLabel()); } }
public DEPNode getRightNearestSibling(int id) { DEPNode node, head = get(id).getHead(); if (head == null) return null; int i, eIdx = (id < head.id) ? head.id : size(); for (i = id + 1; i < eIdx; i++) { node = get(i); if (node.getHead() == head) return node; } return null; }
public DEPNode getLeftNearestSibling(int id) { DEPNode node, head = get(id).getHead(); if (head == null) return null; int i, eIdx = (head.id < id) ? head.id : 0; for (i = id - 1; i > eIdx; i--) { node = get(i); if (node.getHead() == head) return node; } return null; }
/** @return a list of root nodes in this tree. */ public List<DEPNode> getRoots() { List<DEPNode> roots = new ArrayList<DEPNode>(); DEPNode node, root = get(0); int i, size = size(); for (i = 1; i < size; i++) { node = get(i); if (node.getHead() == root) roots.add(node); } return roots; }
public DEPNode getLeftMostDependent(int id, int order) { DEPNode node, head = get(id); int i; for (i = 1; i < id; i++) { node = get(i); if (node.getHead() == head) { if (order == 0) return node; order--; } } return null; }
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; }
public StringIntPair[] getDiff(StringIntPair[] heads) { int i, size = size(); DEPNode node, head; StringIntPair[] diff = new StringIntPair[size]; StringIntPair p; for (i = 1; i < size; i++) { node = get(i); head = node.getHead(); p = heads[i]; if (head != null && head.id != p.i && !node.isLabel(p.s)) diff[i] = new StringIntPair(node.getLabel(), head.id); else diff[i] = new StringIntPair(null, DEPLib.NULL_ID); } return diff; }
/** @return > 0 if w_k is non-projective. */ public int isNonProjective(DEPNode wk) { DEPNode wi = wk.getHead(); if (wi == null) return 0; DEPNode wj; int bId, eId, j; if (wk.id < wi.id) { bId = wk.id; eId = wi.id; } else { bId = wi.id; eId = wk.id; } for (j = bId + 1; j < eId; j++) { wj = get(j); if (!wj.isDescendentOf(wi)) return Math.abs(wi.id - wk.id); } return 0; }