public class AlternateSpanList extends SpanList
SpanNode
tree that can have a multiple trees of child nodes, each with its own probability.
This class has quite a few convenience methods for accessing the first subtree.SpanList
Modifier and Type | Class and Description |
---|---|
private class |
AlternateSpanList.Children |
private static class |
AlternateSpanList.ProbabilityComparator |
Modifier and Type | Field and Description |
---|---|
private static Comparator<AlternateSpanList.Children> |
childComparator |
private List<AlternateSpanList.Children> |
childTrees |
static byte |
ID |
Constructor and Description |
---|
AlternateSpanList()
Create a new AlternateSpanList instance, having a single subtree with probability 1.0.
|
AlternateSpanList(AlternateSpanList otherSpanList) |
AlternateSpanList(SpanNodeReader reader) |
Modifier and Type | Method and Description |
---|---|
AlternateSpanList |
add(int i,
SpanNode node)
Convenience method to add a span node to the child tree at index i.
|
AlternateSpanList |
add(SpanNode node)
Adds a child node to the first subtree of this AlternateSpanList.
|
void |
addChildren(int i,
List<SpanNode> subtree,
double probability)
Adds a possible subtree of this AlternateSpanList, with the given probability, at index i.
|
boolean |
addChildren(List<SpanNode> subtree,
double probability)
Adds a possible subtree of this AlternateSpanList, with the given probability.
|
ListIterator<SpanNode> |
childIterator()
Traverses all immediate children of all subtrees of this AlternateSpanList.
|
ListIterator<SpanNode> |
childIterator(int i)
Traverses all immediate children of the given subtree of this AlternateSpanList.
|
ListIterator<SpanNode> |
childIteratorRecursive()
Recursively traverses all children (not only leaf nodes) of all subtrees of this AlternateSpanList, in a
depth-first fashion.
|
ListIterator<SpanNode> |
childIteratorRecursive(int i)
Recursively traverses all children (not only leaf nodes) of the given subtree of this AlternateSpanList, in a
depth-first fashion.
|
protected List<SpanNode> |
children()
Returns a modifiable
List of child nodes of first subtree. |
protected List<SpanNode> |
children(int i)
Returns a modifiable
List of child nodes of the specified subtree. |
void |
clearChildren()
Clears all subtrees (the subtrees themselves are kept, but their contents are cleared and become invalidated).
|
void |
clearChildren(int i)
Clears a given subtree (the subtree itself is kept, but its contents are cleared and become invalidated).
|
private void |
ensureAtLeastOneSubTree() |
boolean |
equals(Object o) |
int |
getFrom(int i)
Returns the character index where this
SpanNode starts (inclusive), i.e. the smallest SpanNode.getFrom() of all children in subtree i. |
int |
getLength(int i)
Returns the length of this span according to subtree i, i.e. getFrom(i) - getTo(i).
|
int |
getNumSubTrees()
Returns the number of subtrees under this node.
|
double |
getProbability(int i)
Returns the probability of the given subtree.
|
CharSequence |
getText(int i,
CharSequence text)
Returns the text covered by this span as given by subtree i, or null if subtree i is empty.
|
int |
getTo(int i)
Returns the character index where this
SpanNode ends (exclusive), i.e. the greatest SpanNode.getTo() of all children in subtree i. |
int |
hashCode() |
void |
move(int i,
int nodeNum,
AlternateSpanList target,
int targetSubTree)
Moves a child of this SpanList to another SpanList.
|
void |
move(int i,
int nodeNum,
SpanList target)
Moves a child of this SpanList to another SpanList.
|
void |
move(int i,
SpanNode node,
AlternateSpanList target,
int targetSubTree)
Moves a child of this SpanList to another SpanList.
|
void |
move(int i,
SpanNode node,
SpanList target)
Moves a child of this SpanList to another SpanList.
|
void |
normalizeProbabilities()
Normalizes all probabilities between 0.0 (inclusive) and 1.0 (exclusive).
|
int |
numChildren(int i) |
void |
removeChildren()
Removes all subtrees (both the subtrees themselves and their contents, which become invalidated).
|
List<SpanNode> |
removeChildren(int i)
Removes the subtree at index i (both the subtree itself and its contents, which become invalidated).
|
List<SpanNode> |
setChildren(int i,
List<SpanNode> subtree,
double probability)
Sets the subtree at index i.
|
(package private) void |
setInvalid() |
(package private) void |
setParent(SpanNodeParent parent) |
void |
setProbability(int i,
double probability)
Sets the probability of the given subtree.
|
void |
sortChildren()
Sorts children in all subtrees by occurrence in the text covered.
|
void |
sortChildren(int i)
Sorts children in subtree i by occurrence in the text covered.
|
void |
sortChildrenRecursive()
Recursively sorts all children in all subtrees by occurrence in the text covered.
|
void |
sortChildrenRecursive(int i)
Recursively sorts all children in subtree i by occurrence in the text covered.
|
void |
sortSubTreesByProbability()
Sorts the subtrees under this AlternateSpanList by descending probability, such that the most probable
subtree becomes the first subtree, and so on.
|
String |
toString() |
checkValidity, getFrom, getLength, getText, getTo, isLeafNode, move, move, move, move, numChildren, remove, remove, resetCachedFromAndTo, span
annotate, annotate, annotate, annotate, annotate, compareTo, contains, getParent, getScratchId, getSpanTree, getStringFieldValue, isValid, overlaps, setScratchId
public static final byte ID
private final List<AlternateSpanList.Children> childTrees
private static final Comparator<AlternateSpanList.Children> childComparator
public AlternateSpanList()
public AlternateSpanList(AlternateSpanList otherSpanList)
public AlternateSpanList(SpanNodeReader reader)
private void ensureAtLeastOneSubTree()
public AlternateSpanList add(SpanNode node)
sortSubTreesByProbability()
first.public void sortSubTreesByProbability()
protected List<SpanNode> children()
List
of child nodes of first subtree.public int getNumSubTrees()
public void clearChildren()
clearChildren
in class SpanList
public void clearChildren(int i)
i
- the index of the subtree to clearpublic void sortChildren()
sortChildren
in class SpanList
SpanNode.compareTo(SpanNode)
public void sortChildren(int i)
i
- the index of the subtree to sortSpanNode.compareTo(SpanNode)
public void sortChildrenRecursive()
sortChildrenRecursive
in class SpanList
public void sortChildrenRecursive(int i)
i
- the index of the subtree to sort recursivelypublic void move(int i, SpanNode node, SpanList target)
i
- the index of the subtree to remove the node fromnode
- the node to movetarget
- the SpanList to add the node toIllegalArgumentException
- if the given node is not a child of this SpanListpublic void move(int i, int nodeNum, SpanList target)
i
- the index of the subtree to remove the node fromnodeNum
- the index of the node to movetarget
- the SpanList to add the node toIndexOutOfBoundsException
- if the given index is out of rangepublic void move(int i, SpanNode node, AlternateSpanList target, int targetSubTree)
i
- the index of the subtree to remove the node fromnode
- the node to movetarget
- the SpanList to add the node totargetSubTree
- the index of the subtree of the given AlternateSpanList to add the node toIllegalArgumentException
- if the given node is not a child of this SpanListIndexOutOfBoundsException
- if the given index is out of range, or if the target subtree index is out of rangepublic void move(int i, int nodeNum, AlternateSpanList target, int targetSubTree)
i
- the index of the subtree to remove the node fromnodeNum
- the index of the node to movetarget
- the SpanList to add the node totargetSubTree
- the index of the subtree of the given AlternateSpanList to add the node toIndexOutOfBoundsException
- if any of the given indeces are out of range, or the target subtree index is out of rangepublic ListIterator<SpanNode> childIterator()
childIterator
in class SpanList
ListIterator
public ListIterator<SpanNode> childIteratorRecursive()
childIteratorRecursive
in class SpanList
ListIterator
public ListIterator<SpanNode> childIterator(int i)
i
- the index of the subtree to iterate overListIterator
public ListIterator<SpanNode> childIteratorRecursive(int i)
i
- the index of the subtree to iterate overListIterator
public int numChildren(int i)
protected List<SpanNode> children(int i)
List
of child nodes of the specified subtree.i
- the index of the subtree to searchList
of child nodes of the specified subtreevoid setParent(SpanNodeParent parent)
public boolean addChildren(List<SpanNode> subtree, double probability)
subtree
- the subtree to addprobability
- the probability of this subtreechildren()
public void addChildren(int i, List<SpanNode> subtree, double probability)
i
- the index of where to insert the subtreesubtree
- the subtree to addprobability
- the probability of this subtreechildren()
public List<SpanNode> removeChildren(int i)
i
- the index of the subtree to removepublic void removeChildren()
void setInvalid()
setInvalid
in class SpanList
public List<SpanNode> setChildren(int i, List<SpanNode> subtree, double probability)
i
- the index of where to set the subtreesubtree
- the subtree to setprobability
- the probability to setpublic int getFrom(int i)
SpanNode
starts (inclusive), i.e. the smallest SpanNode.getFrom()
of all children in subtree i.i
- the index of the subtree to useIndexOutOfBoundsException
- if this AlternateSpanList has no subtree ipublic int getTo(int i)
SpanNode
ends (exclusive), i.e. the greatest SpanNode.getTo()
of all children in subtree i.i
- the index of the subtree to useIndexOutOfBoundsException
- if this AlternateSpanList has no subtree ipublic int getLength(int i)
i
- the index of the subtree to usepublic CharSequence getText(int i, CharSequence text)
i
- the index of the subtree to usetext
- the text to get a substring frompublic double getProbability(int i)
i
- the subtree to return the probability ofpublic void setProbability(int i, double probability)
i
- the subtree to set the probability ofprobability
- the probability to setpublic void normalizeProbabilities()
public AlternateSpanList add(int i, SpanNode node)
AlternateSpanList.children(i).add(node);
i
- indexnode
- span nodeCopyright © 2018. All rights reserved.