public class Node
extends java.lang.Object
A node is part of Lattices, representing the theory that a word was spoken over a given period of time. A node also
has a set of entering and leaving edges
, connecting it to other nodes. One can get
and set the beginning and end frames of the word via the getBeginTime and getEndTime methods. When setting these
times, the beginning time must be earlier or equal to the end time, otherwise an error will be thrown.
The posterior probability of any word in a word lattice is the probability that the node representing that word
occurs on any path through the lattice. It is usually computed as the ratio of the total likelihood scores of all
paths through the lattice that pass through the node, to the total likelihood score of all paths through the lattice.
Path scores are usually computed using the acoustic likelihoods of the nodes, although language scores can also be
incorporated. The posterior probabilities of an entire lattice is usually computed efficiently using the
Forward-Backward Algorithm. Refer to the computeNodePosteriors
method in the Lattice class for details.
Modifier | Constructor and Description |
---|---|
protected |
Node(java.lang.String id,
Word word,
long beginTime,
long endTime)
Create a new Node with given ID.
|
protected |
Node(Word word,
long beginTime,
long endTime)
Create a new Node
|
Modifier and Type | Method and Description |
---|---|
protected void |
addEnteringEdge(Edge e)
Add an Edge from this Node
|
protected void |
addLeavingEdge(Edge e)
Add an Edge to this Node
|
protected void |
cacheDescendants() |
protected void |
cacheDescendantsHelper(Node n) |
void |
dumpDot(java.io.FileWriter f)
Internal routine when dumping Lattices as Graphviz files
|
boolean |
equals(java.lang.Object obj)
Assumes ids are unique node identifiers
|
Edge |
findEquivalentLeavingEdge(Edge edge)
Returns a leaving edge that is equivalent to the given edge.
|
double |
getBackwardScore()
Returns the backward score, which is calculated during the computation of the posterior score for this node.
|
long |
getBeginTime()
Get the frame number when the word began
|
Node |
getBestPredecessor()
Returns the best predecessor for this node.
|
java.util.List<Node> |
getChildNodes()
Get the nodes at the other ends of outgoing edges of this node.
|
java.util.Collection<Edge> |
getCopyOfEnteringEdges()
Returns a copy of the Edges to this Node, so that the underlying data structure will not be modified.
|
java.util.Collection<Edge> |
getCopyOfLeavingEdges()
Returns a copy of the Edges from this Node, so that the underlying data structure will not be modified.
|
Edge |
getEdgeFromNode(Node n)
given a node find the edge from that node
|
Edge |
getEdgeToNode(Node n)
given a node find the edge to that node
|
long |
getEndTime()
Get the frame number when the word ends
|
java.util.Collection<Edge> |
getEnteringEdges()
Get the Edges to this Node
|
double |
getForwardScore()
Returns the forward score, which is calculated during the computation of the posterior score for this node.
|
java.lang.String |
getId()
Get the ID associated with this Node
|
java.util.Collection<Edge> |
getLeavingEdges()
Get the Edges from this Node
|
protected static java.lang.String |
getNextNodeId()
Get a unique ID for a new Node.
|
double |
getPosterior()
Returns the posterior probability of this node.
|
TimeFrame |
getTimeFrame()
Returns TimeFrame of the Node
|
double |
getViterbiScore()
Returns the Viterbi score for this node.
|
Word |
getWord()
Get the word associated with this Node
|
boolean |
hasAncestralRelationship(Node node)
Check whether this node has an ancestral relationship with another node (i.e. either this node is an ancestor of
the other node, or vice versa)
|
protected boolean |
hasEdgeFromNode(Node n)
Test is a Node has an Edge from a Node
|
protected boolean |
hasEdgeToNode(Node n)
Test if a node has an Edge to a Node
|
protected boolean |
hasEquivalentEnteringEdges(Node n)
Test if a Node has all Edges from the same Nodes and another Node.
|
boolean |
hasEquivalentLeavingEdges(Node n)
Test if a Node has all Edges to the same Nodes and another Node.
|
int |
hashCode() |
protected boolean |
isAncestorHelper(java.util.List<Node> children,
Node node,
java.util.Set<Node> seenNodes) |
boolean |
isAncestorOf(Node node)
Check whether this node is an ancestor of another node.
|
boolean |
isEquivalent(Node other)
Returns true if the given node is equivalent to this node.
|
protected void |
removeEnteringEdge(Edge e)
Remove an Edge from this Node
|
void |
removeLeavingEdge(Edge e)
Remove an Edge to this Node
|
void |
setBackwardScore(double backwardScore)
Sets the backward score for this node.
|
void |
setBeginTime(long beginTime)
Sets the frame number when the word began.
|
void |
setBestPredecessor(Node bestPredecessor)
Sets the best predecessor of this node.
|
void |
setEndTime(long endTime)
Sets the frame number when the words ended.
|
void |
setForwardScore(double forwardScore)
Sets the backward score for this node.
|
void |
setPosterior(double posterior)
Sets the posterior probability of this node.
|
void |
setViterbiScore(double viterbiScore)
Sets the Viterbi score for this node.
|
java.lang.String |
toString()
Returns a description of this Node that contains the word, the start time, and the end time.
|
protected Node(Word word, long beginTime, long endTime)
word
- the word of this nodebeginTime
- the start time of the wordendTime
- the end time of the wordprotected Node(java.lang.String id, Word word, long beginTime, long endTime)
id
- id of the nodeword
- wordbeginTime
- begin timeendTime
- end timeprotected static java.lang.String getNextNodeId()
protected boolean hasEdgeToNode(Node n)
n
- node to checkpublic Edge getEdgeToNode(Node n)
n
- the node of interest null
if no edge could be found.protected boolean hasEdgeFromNode(Node n)
n
- node to checkpublic Edge getEdgeFromNode(Node n)
n
- the node of interest null
if no edge could be found.protected boolean hasEquivalentEnteringEdges(Node n)
n
- node to checkpublic boolean hasEquivalentLeavingEdges(Node n)
n
- the node of interestpublic java.util.Collection<Edge> getEnteringEdges()
public java.util.Collection<Edge> getLeavingEdges()
public java.util.Collection<Edge> getCopyOfEnteringEdges()
public java.util.Collection<Edge> getCopyOfLeavingEdges()
protected void addEnteringEdge(Edge e)
e
- edge to addprotected void addLeavingEdge(Edge e)
e
- edge to addprotected void removeEnteringEdge(Edge e)
e
- edge to removepublic void removeLeavingEdge(Edge e)
e
- the edge to removepublic java.lang.String getId()
public Word getWord()
public long getBeginTime()
public void setBeginTime(long beginTime)
beginTime
- the frame number when the word beganpublic long getEndTime()
public void setEndTime(long endTime)
endTime
- the frame number when the word endedpublic TimeFrame getTimeFrame()
public java.lang.String toString()
toString
in class java.lang.Object
public void dumpDot(java.io.FileWriter f) throws java.io.IOException
f
- file writer to storejava.io.IOException
- if error occurredpublic double getBackwardScore()
public void setBackwardScore(double backwardScore)
backwardScore
- The backwardScore to set.public double getForwardScore()
public void setForwardScore(double forwardScore)
forwardScore
- The forwardScore to set.public double getPosterior()
public void setPosterior(double posterior)
posterior
- The node posterior probability to set.public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
Object.equals(java.lang.Object)
public java.util.List<Node> getChildNodes()
protected void cacheDescendants()
protected void cacheDescendantsHelper(Node n)
protected boolean isAncestorHelper(java.util.List<Node> children, Node node, java.util.Set<Node> seenNodes)
public boolean isAncestorOf(Node node)
node
- the Node to checkpublic boolean hasAncestralRelationship(Node node)
node
- the Node to check for a relationshippublic boolean isEquivalent(Node other)
other
- the Node we're comparing topublic Edge findEquivalentLeavingEdge(Edge edge)
edge
- the Edge to compare the leaving edges of this node againstpublic Node getBestPredecessor()
public void setBestPredecessor(Node bestPredecessor)
bestPredecessor
- The bestPredecessor to set.public double getViterbiScore()
public void setViterbiScore(double viterbiScore)
viterbiScore
- The viterbiScore to set.