Package opennlp.tools.ml
Class BeamSearch.SearchNode
java.lang.Object
opennlp.tools.ml.BeamSearch.SearchNode
- All Implemented Interfaces:
Comparable<BeamSearch.SearchNode>
- Enclosing class:
BeamSearch
private static final class BeamSearch.SearchNode
extends Object
implements Comparable<BeamSearch.SearchNode>
Immutable node in a backward-linked chain of outcome candidates, used only inside
BeamSearch.bestSequences(int, Object[], Object[], double, BeamSearchContextGenerator, SequenceValidator).
A node stores its own outcome, its probability, the accumulated score
parent.score + StrictMath.log(prob) and a parent link, so extending a candidate
is O(1); the full outcome array is materialized only when a candidate is expanded.
Nodes are ordered by compareTo(SearchNode).-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateCreates the root node: the empty candidate with score0.privateSearchNode(BeamSearch.SearchNode parent, String outcome, double prob) Creates a candidate extendingparentby one outcome. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidFills the outcomes, and the probabilities if requested, on the path from the root to this node, in sequence order.intcompareTo(BeamSearch.SearchNode other) Orders nodes by descending score, mirroringSequence.compareTo(Sequence).private String[]outcomes()private Sequence
-
Field Details
-
parent
-
outcome
-
prob
private final double prob -
score
private final double score -
size
private final int size
-
-
Constructor Details
-
SearchNode
private SearchNode()Creates the root node: the empty candidate with score0. -
SearchNode
Creates a candidate extendingparentby one outcome.- Parameters:
parent- The candidate to extend. Must not benull.outcome- The outcome to append.prob- The probability ofoutcome.
-
-
Method Details
-
outcomes
- Returns:
- The outcomes on the path from the root to this node, in sequence order.
-
toSequence
- Returns:
- The
Sequenceof the outcomes and probabilities on the path from the root to this node, in sequence order.
-
collect
Fills the outcomes, and the probabilities if requested, on the path from the root to this node, in sequence order. -
compareTo
Orders nodes by descending score, mirroringSequence.compareTo(Sequence). Exact score ties are broken lexicographically by the outcome chain from the root, so tied candidates expand and are returned in the same canonical order on every run and JVM.PriorityQueuegives no ordering guarantee for elements whose comparison returns0, and ties decide both which candidates survive beam truncation and the order of equal-scored winners.- Specified by:
compareToin interfaceComparable<BeamSearch.SearchNode>
-