|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.cmu.sphinx.linguist.language.grammar.Grammar
edu.cmu.sphinx.jsgf.JSGFGrammar
public class JSGFGrammar
#JSGF V1.0 public <helloWorld> = Hello World;Figure 1: Hello grammar that generates the sentences "Hello World". The above grammar is saved in a file called "hello.gram". It defines a public grammar rule called "helloWorld". In order for this grammar rule to be publicly accessible, we must be declared it "public". Non-public grammar rules are not visible outside of the grammar file. The location of the grammar file(s) is(are) defined by the
baseGrammarURLproperty. Since all JSGF grammar
files end with ".gram", it will automatically search all such files at the
given URL for the grammar. The name of the grammar to search for is specified
by grammarName. In this example, the grammar name
is "helloWorld".
#JSGF V1.0 public <basicCmd> = <startPolite> <command> <endPolite>; <command> = <action> <object>; <action> = /10/ open |/2/ close |/1/ delete |/1/ move; <object> = [the | a] (window | file | menu); <startPolite> = (please | kindly | could you | oh mighty computer) *; <endPolite> = [ please | thanks | thank you ];Figure 2: Command grammar that generates simple control commands. The features of JSGF that are shown in this example includes:
"<sil>" means "silence".
#JSGF V1.0 grammar jsgf.nastygram; public <nasty> = I saw a ((cat* | dog* | mouse*)+)+;the production: ((cat* | dog* | mouse*)+)+ can result in a continuous loop, since (cat* | dog* | mouse*) can represent no speech (i.e. zero cats, dogs and mice), this is equivalent to ()+. To avoid this problem, the grammar writer should ensure that there are no rules that could possibly match no speech within a plus operator or kleene star operator.
| Nested Class Summary | |
|---|---|
(package private) class |
JSGFGrammar.GrammarGraph
Represents a graph of grammar nodes. |
(package private) class |
JSGFGrammar.RuleStack
Manages a stack of grammar graphs that can be accessed by grammar name |
| Field Summary | |
|---|---|
private java.net.URL |
baseURL
|
private GrammarNode |
firstNode
|
private java.lang.String |
grammarName
|
private boolean |
loadGrammar
|
private java.util.logging.Logger |
logger
|
private LogMath |
logMath
|
private JSGFRuleGrammarManager |
manager
|
static java.lang.String |
PROP_BASE_GRAMMAR_URL
The property that defines the location of the JSGF grammar file. |
static java.lang.String |
PROP_GRAMMAR_NAME
The property that defines the location of the JSGF grammar file. |
static java.lang.String |
PROP_LOG_MATH
The property that defines the logMath component. |
private JSGFRuleGrammar |
ruleGrammar
|
private JSGFGrammar.RuleStack |
ruleStack
|
| Fields inherited from class edu.cmu.sphinx.linguist.language.grammar.Grammar |
|---|
dictionary, initialNode, PROP_ADD_FILLER_WORDS, PROP_ADD_SIL_WORDS, PROP_DICTIONARY, PROP_OPTIMIZE_GRAMMAR, PROP_SHOW_GRAMMAR |
| Constructor Summary | |
|---|---|
JSGFGrammar()
|
|
JSGFGrammar(java.lang.String location,
LogMath logMath,
java.lang.String grammarName,
boolean showGrammar,
boolean optimizeGrammar,
boolean addSilenceWords,
boolean addFillerWords,
Dictionary dictionary)
|
|
JSGFGrammar(java.net.URL baseURL,
LogMath logMath,
java.lang.String grammarName,
boolean showGrammar,
boolean optimizeGrammar,
boolean addSilenceWords,
boolean addFillerWords,
Dictionary dictionary)
|
|
| Method Summary | |
|---|---|
void |
commitChanges()
Commit changes to all loaded grammars and all changes of grammar since the last commitChange |
protected GrammarNode |
createGrammar()
Creates the grammar. |
private void |
dumpGrammar()
Dumps interesting things about this grammar |
private java.lang.String |
getFullRuleName(java.lang.String ruleName)
Gets the fully resolved rule name |
JSGFRuleGrammarManager |
getGrammarManager()
Returns manager used to load grammars |
java.lang.String |
getGrammarName()
Returns the name of this grammar. |
GrammarNode |
getInitialNode()
Returns the initial node for the grammar |
private JSGFRuleGrammar |
getNamedRuleGrammar(java.lang.String grammarName)
|
private java.util.List<java.lang.Float> |
getNormalizedWeights(java.util.List<java.lang.Float> weights)
Normalize the weights. |
JSGFRuleGrammar |
getRuleGrammar()
Returns the RuleGrammar of this JSGFGrammar. |
private static java.net.URL |
grammarNameToURL(java.net.URL baseURL,
java.lang.String grammarName)
|
private void |
loadFullQualifiedRules(JSGFRuleGrammar grammar)
Load grammars imported by a fully qualified Rule Token if they are not already loaded. |
private void |
loadImports(JSGFRuleGrammar grammar)
Load grammars imported by the specified RuleGrammar if they are not already loaded. |
void |
loadJSGF(java.lang.String grammarName)
The JSGF grammar specified by grammarName will be loaded from the base url (tossing out any previously loaded grammars) |
private JSGFRuleGrammar |
loadNamedGrammar(java.lang.String grammarName)
Load named grammar from import rule |
void |
newProperties(PropertySheet ps)
This method is called when this configurable component needs to be reconfigured. |
private JSGFGrammar.GrammarGraph |
processRule(JSGFRule rule)
Parses the given Rule into a network of GrammarNodes. |
private JSGFGrammar.GrammarGraph |
processRuleAlternatives(JSGFRuleAlternatives ruleAlternatives)
Parses the given RuleAlternatives into a network of GrammarNodes. |
private JSGFGrammar.GrammarGraph |
processRuleCount(JSGFRuleCount ruleCount)
Parses the given RuleCount into a network of GrammarNodes. |
private JSGFGrammar.GrammarGraph |
processRuleName(JSGFRuleName initialRuleName)
Parses the given RuleName into a network of GrammarNodes. |
private JSGFGrammar.GrammarGraph |
processRuleSequence(JSGFRuleSequence ruleSequence)
Parses the given RuleSequence into a network of GrammarNodes. |
private JSGFGrammar.GrammarGraph |
processRuleTag(JSGFRuleTag ruleTag)
Parses the given RuleTag into a network GrammarNodes. |
private JSGFGrammar.GrammarGraph |
processRuleToken(JSGFRuleToken ruleToken)
Creates a GrammarNode with the word in the given RuleToken. |
void |
setBaseURL(java.net.URL url)
Sets the URL context of the JSGF grammars. |
| Methods inherited from class edu.cmu.sphinx.linguist.language.grammar.Grammar |
|---|
allocate, createGrammar, createGrammarNode, createGrammarNode, createGrammarNode, createGrammarNode, createGrammarNode, deallocate, dumpGrammar, dumpRandomSentences, dumpRandomSentences, dumpStatistics, getDictionary, getGrammarNodes, getNumNodes, getRandomSentence, newGrammar, postProcessGrammar |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
@S4String public static final java.lang.String PROP_BASE_GRAMMAR_URL
@S4String(defaultValue="default.gram") public static final java.lang.String PROP_GRAMMAR_NAME
@S4Component(type=LogMath.class) public static final java.lang.String PROP_LOG_MATH
private JSGFRuleGrammar ruleGrammar
private JSGFRuleGrammarManager manager
private JSGFGrammar.RuleStack ruleStack
private java.lang.String grammarName
private java.net.URL baseURL
private LogMath logMath
private boolean loadGrammar
private GrammarNode firstNode
private java.util.logging.Logger logger
| Constructor Detail |
|---|
public JSGFGrammar(java.lang.String location,
LogMath logMath,
java.lang.String grammarName,
boolean showGrammar,
boolean optimizeGrammar,
boolean addSilenceWords,
boolean addFillerWords,
Dictionary dictionary)
throws java.net.MalformedURLException,
java.lang.ClassNotFoundException
java.net.MalformedURLException
java.lang.ClassNotFoundException
public JSGFGrammar(java.net.URL baseURL,
LogMath logMath,
java.lang.String grammarName,
boolean showGrammar,
boolean optimizeGrammar,
boolean addSilenceWords,
boolean addFillerWords,
Dictionary dictionary)
public JSGFGrammar()
| Method Detail |
|---|
public void newProperties(PropertySheet ps)
throws PropertyException
Configurable
newProperties in interface ConfigurablenewProperties in class Grammarps - a property sheet holding the new data
PropertyException - if there is a problem with the properties.public JSGFRuleGrammar getRuleGrammar()
public JSGFRuleGrammarManager getGrammarManager()
public void setBaseURL(java.net.URL url)
url - the URL context of the grammarspublic java.lang.String getGrammarName()
public void loadJSGF(java.lang.String grammarName)
throws java.io.IOException,
JSGFGrammarParseException,
JSGFGrammarException
grammarName - the name of the grammar
java.io.IOException - if an error occurs while loading or compiling the grammar
JSGFGrammarException
JSGFGrammarParseException
protected GrammarNode createGrammar()
throws java.io.IOException
createGrammar in class Grammarjava.io.IOException - if the grammar could not be loadedpublic GrammarNode getInitialNode()
getInitialNode in interface GrammarInterfacegetInitialNode in class Grammar
private JSGFGrammar.GrammarGraph processRule(JSGFRule rule)
throws JSGFGrammarException
rule - the Rule to parse
JSGFGrammarException
private JSGFGrammar.GrammarGraph processRuleName(JSGFRuleName initialRuleName)
throws JSGFGrammarException
initialRuleName - the RuleName rule to parse
JSGFGrammarException
private JSGFGrammar.GrammarGraph processRuleCount(JSGFRuleCount ruleCount)
throws JSGFGrammarException
ruleCount - the RuleCount object to parse
JSGFGrammarException
private JSGFGrammar.GrammarGraph processRuleAlternatives(JSGFRuleAlternatives ruleAlternatives)
throws JSGFGrammarException
ruleAlternatives - the RuleAlternatives to parse
JSGFGrammarExceptionprivate java.util.List<java.lang.Float> getNormalizedWeights(java.util.List<java.lang.Float> weights)
weights - the weights to normalize
private JSGFGrammar.GrammarGraph processRuleSequence(JSGFRuleSequence ruleSequence)
throws JSGFGrammarException
ruleSequence - the RuleSequence to parse
JSGFGrammarException
private JSGFGrammar.GrammarGraph processRuleTag(JSGFRuleTag ruleTag)
throws JSGFGrammarException
ruleTag - the RuleTag to parse
JSGFGrammarExceptionprivate JSGFGrammar.GrammarGraph processRuleToken(JSGFRuleToken ruleToken)
ruleToken - the RuleToken that contains the word
private static java.net.URL grammarNameToURL(java.net.URL baseURL,
java.lang.String grammarName)
throws java.net.MalformedURLException
java.net.MalformedURLException
public void commitChanges()
throws java.io.IOException,
JSGFGrammarParseException,
JSGFGrammarException
JSGFGrammarParseException
JSGFGrammarException
java.io.IOException
private void loadImports(JSGFRuleGrammar grammar)
throws java.io.IOException,
JSGFGrammarParseException
JSGFGrammarParseException
java.io.IOExceptionprivate JSGFRuleGrammar getNamedRuleGrammar(java.lang.String grammarName)
private JSGFRuleGrammar loadNamedGrammar(java.lang.String grammarName)
throws JSGFGrammarParseException,
java.io.IOException
grammarName -
JSGFGrammarParseException
java.io.IOException
private void loadFullQualifiedRules(JSGFRuleGrammar grammar)
throws java.io.IOException,
JSGFGrammarParseException
grammar -
java.io.IOException
GrammarException
JSGFGrammarParseException
private java.lang.String getFullRuleName(java.lang.String ruleName)
throws JSGFGrammarException
ruleName - the partial name
JSGFGrammarExceptionprivate void dumpGrammar()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||