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

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

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

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 boolean PROP_ADD_FILLER_WORDS_DEFAULT
          The default value for PROP_ADD_FILLER_WORDS
static java.lang.String PROP_ADD_SIL_WORDS
          Property to control whether silence words are inserted into the graph
static boolean PROP_ADD_SIL_WORDS_DEFAULT
          The default value for PROP_ADD_SIL_WORDS
static java.lang.String PROP_DICTIONARY
          Property that defines the dictionary to use for this grammar
static java.lang.String PROP_OPTIMIZE_GRAMMAR
          Property to control whether grammars are optimized or not
static boolean PROP_OPTIMIZE_GRAMMAR_DEFAULT
          The default value for PROP_OPTIMIZE_GRAMMAR
static java.lang.String PROP_SHOW_GRAMMAR
          Property to control the the dumping of the grammar
static boolean PROP_SHOW_GRAMMAR_DEFAULT
          The default value for PROP_SHOW_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
 java.util.Set getGrammarNodes()
          returns the set of of nodes in this grammar
 GrammarNode getInitialNode()
          Returns the initial node for the grammar
 java.lang.String getName()
          Retrieves the name for this configurable component
 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 has new data.
 void register(java.lang.String name, Registry registry)
          Register my properties.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_SHOW_GRAMMAR

public static final java.lang.String PROP_SHOW_GRAMMAR
Property to control the the dumping of the grammar

See Also:
Constant Field Values

PROP_SHOW_GRAMMAR_DEFAULT

public static final boolean PROP_SHOW_GRAMMAR_DEFAULT
The default value for PROP_SHOW_GRAMMAR.

See Also:
Constant Field Values

PROP_OPTIMIZE_GRAMMAR

public static final java.lang.String PROP_OPTIMIZE_GRAMMAR
Property to control whether grammars are optimized or not

See Also:
Constant Field Values

PROP_OPTIMIZE_GRAMMAR_DEFAULT

public static final boolean PROP_OPTIMIZE_GRAMMAR_DEFAULT
The default value for PROP_OPTIMIZE_GRAMMAR

See Also:
Constant Field Values

PROP_ADD_SIL_WORDS

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_SIL_WORDS_DEFAULT

public static final boolean PROP_ADD_SIL_WORDS_DEFAULT
The default value for PROP_ADD_SIL_WORDS

See Also:
Constant Field Values

PROP_ADD_FILLER_WORDS

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_ADD_FILLER_WORDS_DEFAULT

public static final boolean PROP_ADD_FILLER_WORDS_DEFAULT
The default value for PROP_ADD_FILLER_WORDS

See Also:
Constant Field Values

PROP_DICTIONARY

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

register

public void register(java.lang.String name,
                     Registry registry)
              throws PropertyException
Description copied from interface: Configurable
Register my properties. This method is called once early in the time of the component, shortly after the component is constructed. This component should register any configuration properties that it needs to register. If this configurable extends another configurable, super.register should also be called

Specified by:
register in interface Configurable
Parameters:
name - the name of the component
registry - the registry for this component
Throws:
PropertyException

newProperties

public void newProperties(PropertySheet ps)
                   throws PropertyException
Description copied from interface: Configurable
This method is called when this configurable component has new data. The component should first validate the data. If it is bad the component should return false. If the data is good, the component should record the the data internally and return true.

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.

getName

public java.lang.String getName()
Description copied from interface: Configurable
Retrieves the name for this configurable component

Specified by:
getName in interface Configurable
Returns:
the name

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

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 getGrammarNodes()
returns the set of of nodes in this grammar

Returns:
the set of nodes