private void ensureAtLeastOneSubTree() { if (childTrees.isEmpty()) { childTrees.add(new Children(getParent())); } }
/** * Adds a possible subtree of this AlternateSpanList, with the given probability. Note that the first subtree is * always available through the use of children(), so this method is only used for adding the second or higher * subtree. * * @param subtree the subtree to add * @param probability the probability of this subtree * @return true if successful * @see #children() */ public boolean addChildren(List<SpanNode> subtree, double probability) { Children childTree = new Children(getParent(), subtree, probability); resetCachedFromAndTo(); return childTrees.add(childTree); }
/** * Adds a possible subtree of this AlternateSpanList, with the given probability, at index i. Note that the first subtree is * always available through the use of children(), so this method is only used for adding the second or higher * subtree. * * @param i the index of where to insert the subtree * @param subtree the subtree to add * @param probability the probability of this subtree * @see #children() */ public void addChildren(int i, List<SpanNode> subtree, double probability) { Children childTree = new Children(getParent(), subtree, probability); resetCachedFromAndTo(); childTrees.add(i, childTree); }
/** * 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; }