edu.cmu.sphinx.linguist.language.grammar
Class GrammarNode

java.lang.Object
  extended byedu.cmu.sphinx.linguist.language.grammar.GrammarNode

public class GrammarNode
extends java.lang.Object

Represents a grammar node in a grammar. A grammar is represented as a graph of grammar nodes and arcs. A grammar node usually represents a word or words, but it can also be a transition point or simply silence. Note that all probabilties are maintained in the LogMath log base


Constructor Summary
GrammarNode(int id, Word[][] alternatives)
          Creates a GrammarNode with the given ID, Words.
 
Method Summary
 void add(GrammarNode node, float logProbability)
          Adds an arc to the given node
 void dump()
          Dumps the grammar
 void dumpGDL(java.lang.String path)
          Dumps the grammar in GDL form
 Word[][] getAlternatives()
          Retrieves the words associated with this grammar node
 int getID()
          Returns the ID of this GrammarNode.
 int getNumAlternatives()
          Gets the number of alternatives
 GrammarArc[] getSuccessors()
          Retrieves the set of transitions out of this node
 Word getWord()
          Retrieve the single word associated with this grammar
 Word[] getWords(int alternative)
          Retrieves the words associated with a specific alternative
 boolean isEmpty()
          Determines if this grammar node is empty (that is, has no words).
 boolean isFinalNode()
          Determines if this grammar node is a final node in the grammar
 void setFinalNode(boolean isFinal)
          Sets the 'final' state of the grammar node.
 java.lang.String toString()
          Returns the string representation of this object
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GrammarNode

public GrammarNode(int id,
                   Word[][] alternatives)
Creates a GrammarNode with the given ID, Words. A GrammarNode with words is, by default, neither a silence nor a final node.

Parameters:
id - the identity of this GrammarNode
alternatives - the set of Words in this GrammarNode. This is a two dimensional array, the first index corresponds to the set of alternative choices, the second index corresponds to a particular word for the alternative
Method Detail

getID

public int getID()
Returns the ID of this GrammarNode.

Returns:
the ID of this GrammarNode

getAlternatives

public Word[][] getAlternatives()
Retrieves the words associated with this grammar node

Returns:
the words associated with this grammar node

getWords

public Word[] getWords(int alternative)
Retrieves the words associated with a specific alternative

Parameters:
alternative - the index of the alternative
Returns:
the words associated with this grammar node

getWord

public Word getWord()
Retrieve the single word associated with this grammar

Returns:
the word associated with this grammar node

getNumAlternatives

public int getNumAlternatives()
Gets the number of alternatives

Returns:
the number of alternatives

isEmpty

public boolean isEmpty()
Determines if this grammar node is empty (that is, has no words).

Returns:
true if the node is empty, otherwise false.

getSuccessors

public GrammarArc[] getSuccessors()
Retrieves the set of transitions out of this node

Returns:
the transitions to the successors for this node.

isFinalNode

public boolean isFinalNode()
Determines if this grammar node is a final node in the grammar

Returns:
true if the node is a final node in the grammar

setFinalNode

public void setFinalNode(boolean isFinal)
Sets the 'final' state of the grammar node. A 'final' state grammar marks the end of a grammar

Parameters:
isFinal - if true the grammar node is a final node.

add

public void add(GrammarNode node,
                float logProbability)
Adds an arc to the given node

Parameters:
node - the node that this new arc goes to
logProbability - the log probability of the transition occuring

toString

public java.lang.String toString()
Returns the string representation of this object


dumpGDL

public void dumpGDL(java.lang.String path)
Dumps the grammar in GDL form

Parameters:
path - the path to write the gdl file to

dump

public void dump()
Dumps the grammar