/** * Sorts children in subtree i by occurrence in the text covered. * * @param i the index of the subtree to sort * @see SpanNode#compareTo(SpanNode) */ public void sortChildren(int i) { Children children = childTrees.get(i); Collections.sort(children.children()); }
/** * Sorts children in <strong>all</strong> subtrees by occurrence in the text covered. * * @see SpanNode#compareTo(SpanNode) */ @Override public void sortChildren() { for (Children children : childTrees) { Collections.sort(children.children()); } }
/** * Returns a modifiable {@link List} of child nodes of the specified subtree. * * @param i the index of the subtree to search * @return a modifiable {@link List} of child nodes of the specified subtree */ protected List<SpanNode> children(int i) { return childTrees.get(i).children(); }
/** * Sets the subtree at index i. * * @param i the index of where to set the subtree * @param subtree the subtree to set * @param probability the probability to set * @return the overwritten subtree, if any */ public List<SpanNode> setChildren(int i, List<SpanNode> subtree, double probability) { resetCachedFromAndTo(); if (childTrees.size() == 1 && i == 0) { //replace the first subtree Children sub = new Children(getParent(), subtree, probability); Children retval = childTrees.set(i, sub); if (retval == null) { return null; } else { retval.setParent(null); for (SpanNode node : retval.children()) { node.setParent(null); } return retval.children(); } } List<SpanNode> retval = removeChildren(i); addChildren(i, subtree, probability); return retval; }
public AlternateSpanList(AlternateSpanList otherSpanList) { super((List<SpanNode>) null); for (Children otherSubtree : otherSpanList.childTrees) { //create our own subtree: Children children = new Children(this); //copy nodes: for (SpanNode otherNode : otherSubtree.children()) { if (otherNode instanceof Span) { children.add(new Span((Span) otherNode)); } else if (otherNode instanceof AlternateSpanList) { children.add(new AlternateSpanList((AlternateSpanList) otherNode)); } else if (otherNode instanceof SpanList) { children.add(new SpanList((SpanList) otherNode)); } else if (otherNode instanceof DummySpanNode) { children.add(otherNode); //shouldn't really happen } else { throw new IllegalStateException("Cannot create copy of " + otherNode + " with class " + ((otherNode == null) ? "null" : otherNode.getClass())); } } //add this subtree to our subtrees: childTrees.add(children); } }
/** * Removes the subtree at index i (both the subtree itself and its contents, which become invalidated). * Note that if this AlternateSpanList has only one subtree and index 0 is given, * a new empty subtree is automatically added, since an AlternateSpanList always has at least one subtree. * * @param i the index of the subtree to remove * @return the subtree removed, if any (note: invalidated) */ public List<SpanNode> removeChildren(int i) { Children retval = childTrees.remove(i); ensureAtLeastOneSubTree(); resetCachedFromAndTo(); if (retval != null) { retval.setInvalid(); retval.setParent(null); for (SpanNode node : retval.children()) { node.setParent(null); } return retval.children(); } return null; }
/** * Recursively sorts all children in subtree i by occurrence in the text covered. * * @param i the index of the subtree to sort recursively */ public void sortChildrenRecursive(int i) { Children children = childTrees.get(i); for (SpanNode node : children.children()) { if (node instanceof SpanList) { ((SpanList) node).sortChildrenRecursive(); } } Collections.sort(children.children()); }
/** * Recursively sorts all children in <strong>all</strong> subtrees by occurrence in the text covered. */ public void sortChildrenRecursive() { for (Children children : childTrees) { for (SpanNode node : children.children()) { if (node instanceof SpanList) { ((SpanList) node).sortChildrenRecursive(); } } Collections.sort(children.children()); } }