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

java.lang.Object
  extended by edu.cmu.sphinx.linguist.language.grammar.Grammar
All Implemented Interfaces:
GrammarInterface, Configurable
Direct Known Subclasses:
ForcedAlignerGrammar, FSTGrammar, LMGrammar, SimpleWordListGrammar

public abstract class Grammar
extends java.lang.Object
implements Configurable, GrammarInterface

Classes that implement this interface create grammars. A grammar is represented internally as a graph of GrammarNodes linked together by GrammarArcs. Calling getInitialNode will return the first node of the grammar graph. To traverse the grammar graph, one should call GrammarNode.getSuccessors, which will return an array of GrammarArcs, from which you can reach the neighboring GrammarNodes.

Note that all grammar probabilities are maintained in LogMath log domain.


Field Summary
static java.lang.String PROP_ADD_FILLER_WORDS
          Property to control whether filler words are inserted into the graph
static java.lang.String PROP_ADD_SIL_WORDS
          Property to control whether silence words are inserted into the graph
static java.lang.String PROP_DICTIONARY
          Property that defines the dictionary to use for this grammar
static java.lang.String PROP_OPTIMIZE_GRAMMAR
          The default value for PROP_SHOW_GRAMMAR.
static java.lang.String PROP_SHOW_GRAMMAR
          Property to control the the dumping of the grammar
 
Constructor Summary
Grammar()
           
 
Method Summary
 void allocate()
          Create the grammar
 void deallocate()
          Deallocate resources allocated to this grammar
 void dumpGrammar(java.lang.String name)
          Dumps the grammar
 void dumpRandomSentences(int count)
          Dump a set of random sentences that fit this grammar
 void dumpRandomSentences(java.lang.String path, int count)
          Dump a set of random sentences that fit this grammar
 void dumpStatistics()
          Dumps statistics for this grammar
 Dictionary getDictionary()
          Gets the dictionary for this grammar
 java.util.Set<GrammarNode> getGrammarNodes()
          returns the set of of nodes in this grammar
 GrammarNode getInitialNode()
          Returns the initial node for the grammar
 int getNumNodes()
          returns the number of nodes in this grammar
 java.lang.String getRandomSentence()
          Returns a random sentence that fits this grammar
 void newProperties(PropertySheet ps)
          This method is called when this configurable component needs to be reconfigured.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_SHOW_GRAMMAR

@S4Boolean(defaultValue=false)
public static final java.lang.String PROP_SHOW_GRAMMAR
Property to control the the dumping of the grammar

See Also:
Constant Field Values

PROP_OPTIMIZE_GRAMMAR

@S4Boolean(defaultValue=true)
public static final java.lang.String PROP_OPTIMIZE_GRAMMAR
The default value for PROP_SHOW_GRAMMAR.

See Also:
Constant Field Values

PROP_ADD_SIL_WORDS

@S4Boolean(defaultValue=false)
public static final java.lang.String PROP_ADD_SIL_WORDS
Property to control whether silence words are inserted into the graph

See Also:
Constant Field Values

PROP_ADD_FILLER_WORDS

@S4Boolean(defaultValue=false)
public static final java.lang.String PROP_ADD_FILLER_WORDS
Property to control whether filler words are inserted into the graph

See Also:
Constant Field Values

PROP_DICTIONARY

@S4Component(type=Dictionary.class)
public static final java.lang.String PROP_DICTIONARY
Property that defines the dictionary to use for this grammar

See Also:
Constant Field Values
Constructor Detail

Grammar

public Grammar()
Method Detail

newProperties

public void newProperties(PropertySheet ps)
                   throws PropertyException
Description copied from interface: Configurable
This method is called when this configurable component needs to be reconfigured.

Specified by:
newProperties in interface Configurable
Parameters:
ps - a property sheet holding the new data
Throws:
PropertyException - if there is a problem with the properties.

allocate

public void allocate()
              throws java.io.IOException
Create the grammar

Throws:
java.io.IOException

deallocate

public void deallocate()
Deallocate resources allocated to this grammar


getInitialNode

public GrammarNode getInitialNode()
Returns the initial node for the grammar

Specified by:
getInitialNode in interface GrammarInterface
Returns:
the initial grammar node

dumpStatistics

public void dumpStatistics()
Dumps statistics for this grammar


dumpRandomSentences

public void dumpRandomSentences(java.lang.String path,
                                int count)
Dump a set of random sentences that fit this grammar

Parameters:
path - the name of the file to dump the sentences to
count - dumps no more than this. May dump less than this depending upon the number of uniqe sentences in the grammar.

dumpRandomSentences

public void dumpRandomSentences(int count)
Dump a set of random sentences that fit this grammar

Parameters:
count - dumps no more than this. May dump less than this depending upon the number of uniqe sentences in the grammar.

getRandomSentence

public java.lang.String getRandomSentence()
Returns a random sentence that fits this grammar

Returns:
a random sentence that fits this grammar

dumpGrammar

public void dumpGrammar(java.lang.String name)
Dumps the grammar


getNumNodes

public int getNumNodes()
returns the number of nodes in this grammar

Returns:
the number of nodes

getGrammarNodes

public java.util.Set<GrammarNode> getGrammarNodes()
returns the set of of nodes in this grammar

Specified by:
getGrammarNodes in interface GrammarInterface
Returns:
the set of nodes

getDictionary

public Dictionary getDictionary()
Gets the dictionary for this grammar

Returns:
the dictionary