edu.cmu.sphinx.result
Class Node

java.lang.Object
  extended by edu.cmu.sphinx.result.Node

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.


Method Summary
 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.
 int getBeginTime()
          Get the frame number when the word began
 Node getBestPredecessor()
          Returns the best predecessor for this node.
 java.util.List getChildNodes()
          Get the nodes at the other ends of outgoing edges of this node.
 java.util.Collection 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
 int getEndTime()
          Get the frame number when the word ends
 java.util.Collection 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 getLeavingEdges()
          Get the Edges from this Node
 double getPosterior()
          Returns the posterior probability of this 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)
 boolean hasEquivalentLeavingEdges(Node n)
          Test if a Node has all Edges to the same Nodes and another Node.
 int hashCode()
           
 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.
 void removeLeavingEdge(Edge e)
          Remove an Edge to this Node
 void setBackwardScore(double backwardScore)
          Sets the backward score for this node.
 void setBeginTime(int beginTime)
          Sets the frame number when the word began.
 void setBestPredecessor(Node bestPredecessor)
          Sets the best predecessor of this node.
 void setEndTime(int 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.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getEdgeToNode

public Edge getEdgeToNode(Node n)
given a node find the edge to that node

Parameters:
n - the node of interest
Returns:
the edge to that node or null if no edge could be found.

getEdgeFromNode

public Edge getEdgeFromNode(Node n)
given a node find the edge from that node

Parameters:
n - the node of interest
Returns:
the edge from that node or null if no edge could be found.

hasEquivalentLeavingEdges

public boolean hasEquivalentLeavingEdges(Node n)
Test if a Node has all Edges to the same Nodes and another Node.

Parameters:
n - the node of interest
Returns:
true if this Node has all Edges to the sames Nodes as n

getEnteringEdges

public java.util.Collection getEnteringEdges()
Get the Edges to this Node

Returns:
Edges to this Node

getLeavingEdges

public java.util.Collection getLeavingEdges()
Get the Edges from this Node

Returns:
Edges from this Node

getCopyOfLeavingEdges

public java.util.Collection getCopyOfLeavingEdges()
Returns a copy of the Edges from this Node, so that the underlying data structure will not be modified.

Returns:
a copy of the edges from this node

removeLeavingEdge

public void removeLeavingEdge(Edge e)
Remove an Edge to this Node

Parameters:
e - the edge to remove

getId

public java.lang.String getId()
Get the ID associated with this Node

Returns:
the ID

getWord

public Word getWord()
Get the word associated with this Node

Returns:
the word

getBeginTime

public int getBeginTime()
Get the frame number when the word began

Returns:
the begin frame number, or -1 if the frame number is unknown

setBeginTime

public void setBeginTime(int beginTime)
Sets the frame number when the word began. The begin time must be not be later than the time returned by the getEndTime() method, otherwise an error will be thrown.

Parameters:
beginTime - the frame number when the word began

getEndTime

public int getEndTime()
Get the frame number when the word ends

Returns:
the end time, or -1 if the frame number if is unknown

setEndTime

public void setEndTime(int endTime)
Sets the frame number when the words ended. The end time must not be earlier than the time returned by the getEndTime() method, otherwise an error will be thrown.

Parameters:
endTime - the frame number when the word ended

toString

public java.lang.String toString()
Returns a description of this Node that contains the word, the start time, and the end time.

Overrides:
toString in class java.lang.Object
Returns:
a description of this Node

getBackwardScore

public double getBackwardScore()
Returns the backward score, which is calculated during the computation of the posterior score for this node.

Returns:
Returns the backwardScore.

setBackwardScore

public void setBackwardScore(double backwardScore)
Sets the backward score for this node.

Parameters:
backwardScore - The backwardScore to set.

getForwardScore

public double getForwardScore()
Returns the forward score, which is calculated during the computation of the posterior score for this node.

Returns:
Returns the forwardScore.

setForwardScore

public void setForwardScore(double forwardScore)
Sets the backward score for this node.

Parameters:
forwardScore - The forwardScore to set.

getPosterior

public double getPosterior()
Returns the posterior probability of this node. Refer to the javadocs for this class for a description of posterior probabilities.

Returns:
Returns the posterior probability of this node.

setPosterior

public void setPosterior(double posterior)
Sets the posterior probability of this node. Refer to the javadocs for this class for a description of posterior probabilities.

Parameters:
posterior - The node posterior probability to set.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

equals

public boolean equals(java.lang.Object obj)
Assumes ids are unique node identifiers

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

getChildNodes

public java.util.List getChildNodes()
Get the nodes at the other ends of outgoing edges of this node.

Returns:
a list of child nodes

isAncestorOf

public boolean isAncestorOf(Node node)
Check whether this node is an ancestor of another node.

Parameters:
node - the Node to check
Returns:
whether this node is an ancestor of the passed in node.

hasAncestralRelationship

public 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)

Parameters:
node - the Node to check for a relationship
Returns:
whether a relationship exists

isEquivalent

public boolean isEquivalent(Node other)
Returns true if the given node is equivalent to this node. Two nodes are equivalent only if they have the same word, the same number of entering and leaving edges, and that their begin and end times are the same.

Parameters:
other - the Node we're comparing to
Returns:
true if the Node is equivalent; false otherwise

findEquivalentLeavingEdge

public Edge findEquivalentLeavingEdge(Edge edge)
Returns a leaving edge that is equivalent to the given edge. Two edges are eqivalent if Edge.isEquivalent() returns true.

Parameters:
edge - the Edge to compare the leaving edges of this node against
Returns:
an equivalent edge, if any; or null if no equivalent edge

getBestPredecessor

public Node getBestPredecessor()
Returns the best predecessor for this node.

Returns:
Returns the bestPredecessor.

setBestPredecessor

public void setBestPredecessor(Node bestPredecessor)
Sets the best predecessor of this node.

Parameters:
bestPredecessor - The bestPredecessor to set.

getViterbiScore

public double getViterbiScore()
Returns the Viterbi score for this node. The Viterbi score is usually computed during the speech recognition process.

Returns:
Returns the viterbiScore.

setViterbiScore

public void setViterbiScore(double viterbiScore)
Sets the Viterbi score for this node. The Viterbi score is usually computed during the speech recognition process.

Parameters:
viterbiScore - The viterbiScore to set.