public class JSGFRuleGrammar
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.util.List<java.lang.String> |
importedRules |
protected java.util.List<JSGFRuleName> |
imports |
protected java.util.Map<java.lang.String,edu.cmu.sphinx.jsgf.JSGFRuleGrammar.JSGFRuleState> |
rules |
protected java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> |
ruleTags |
Constructor and Description |
---|
JSGFRuleGrammar(java.lang.String name,
JSGFRuleGrammarManager manager)
Create a new RuleGrammar
|
Modifier and Type | Method and Description |
---|---|
void |
addGrammarDocComment(java.lang.String comment)
Add the Grammar comment.
|
void |
addImport(JSGFRuleName importName)
Import all rules or a specified rule from another grammar.
|
void |
addImportDocComment(JSGFRuleName imp,
java.lang.String comment)
Add a new import comment.
|
void |
addRuleDocComment(java.lang.String rname,
java.lang.String comment)
Add a new RuleGrammar comment.
|
void |
addSampleSentence(java.lang.String ruleName,
java.lang.String sample)
add a sample sentence to the list of sample sentences that go with the
specified rule
|
void |
deleteRule(java.lang.String ruleName)
Delete a rule from the grammar.
|
java.lang.String |
getGrammarDocComment()
Retrieve the Grammar comment.
|
java.lang.String |
getImportDocComment(JSGFRuleName imp)
Retrieve an import comment.
|
java.util.List<JSGFRuleName> |
getImports()
List the current imports.
|
java.util.Collection<java.lang.String> |
getJSGFTags(java.lang.String ruleName)
Returns the jsgf tags associated to the given rule.
|
java.lang.String |
getName() |
JSGFRule |
getRule(java.lang.String ruleName)
Return the data structure for the named rule.
|
java.lang.String |
getRuleDocComment(java.lang.String rname)
Retrieve a RuleGrammar comment.
|
java.util.Set<java.lang.String> |
getRuleNames()
List the names of all rules define in this Grammar.
|
boolean |
isEnabled(java.lang.String ruleName) |
boolean |
isRuleChanged(java.lang.String ruleName) |
boolean |
isRulePublic(java.lang.String ruleName)
Test whether the specified rule is public.
|
void |
removeImport(JSGFRuleName importName)
Remove an import.
|
JSGFRuleName |
resolve(JSGFRuleName ruleName)
Resolve a simple or qualified rule name as a full rule name.
|
void |
resolveAllRules()
Resolve and link up all rule references contained in all rules.
|
protected void |
resolveRule(JSGFRule r)
Resolve the given rule.
|
void |
saveJSGF(java.net.URL url)
This JSGFRule grammar will be saved to the file in the provided URL,
Overwriting any contents in the provided file, or creating a new one if
it does not exist.
|
void |
setEnabled(boolean enabled)
Set the enabled property of the Grammar.
|
void |
setEnabled(java.lang.String ruleName,
boolean enabled)
Set the enabled state of the listed rule.
|
void |
setRule(java.lang.String ruleName,
JSGFRule rule,
boolean isPublic)
Set a rule in the grammar either by creating a new rule or updating an
existing rule.
|
void |
setRuleChanged(java.lang.String ruleName,
boolean changed) |
java.lang.String |
toString()
Returns a string containing the specification for this grammar.
|
protected final java.util.Map<java.lang.String,edu.cmu.sphinx.jsgf.JSGFRuleGrammar.JSGFRuleState> rules
protected final java.util.List<JSGFRuleName> imports
protected final java.util.List<java.lang.String> importedRules
protected final java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> ruleTags
public JSGFRuleGrammar(java.lang.String name, JSGFRuleGrammarManager manager)
name
- the name of this Grammar.manager
- the manager for the created Grammarspublic void addGrammarDocComment(java.lang.String comment)
comment
- text for commentpublic void addImport(JSGFRuleName importName)
importName
- the name of the rule(s) to import.public void addImportDocComment(JSGFRuleName imp, java.lang.String comment)
imp
- import namecomment
- comment to addpublic void addRuleDocComment(java.lang.String rname, java.lang.String comment)
rname
- rule doc namecomment
- comment to addpublic void addSampleSentence(java.lang.String ruleName, java.lang.String sample)
ruleName
- name of the rulesample
- sample sentencepublic void deleteRule(java.lang.String ruleName) throws java.lang.IllegalArgumentException
ruleName
- the name of the rule.java.lang.IllegalArgumentException
public java.lang.String getGrammarDocComment()
public java.lang.String getImportDocComment(JSGFRuleName imp)
imp
- rule namepublic java.util.Collection<java.lang.String> getJSGFTags(java.lang.String ruleName)
ruleName
- name of the rulepublic java.lang.String getName()
public JSGFRule getRule(java.lang.String ruleName)
ruleName
- the name of the rule.public java.lang.String getRuleDocComment(java.lang.String rname)
rname
- name of the commentpublic boolean isRulePublic(java.lang.String ruleName) throws java.lang.IllegalArgumentException
ruleName
- the name of the rule.java.lang.IllegalArgumentException
public java.util.List<JSGFRuleName> getImports()
public java.util.Set<java.lang.String> getRuleNames()
public void removeImport(JSGFRuleName importName)
importName
- the name of the rule(s) to remove.public JSGFRuleName resolve(JSGFRuleName ruleName) throws JSGFGrammarException
ruleName
- the name of the rule.JSGFGrammarException
- an exception occuredpublic void resolveAllRules() throws JSGFGrammarException
JSGFGrammarException
- an exception occuredprotected void resolveRule(JSGFRule r) throws JSGFGrammarException
r
- rule to resolveJSGFGrammarException
- if something occurspublic void setEnabled(boolean enabled)
enabled
- the new desired state of the enabled property.public boolean isEnabled(java.lang.String ruleName)
public void setEnabled(java.lang.String ruleName, boolean enabled) throws java.lang.IllegalArgumentException
ruleName
- the name of the rule.enabled
- the new enabled state.java.lang.IllegalArgumentException
public void setRule(java.lang.String ruleName, JSGFRule rule, boolean isPublic) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
ruleName
- the name of the rule.rule
- the definition of the rule.isPublic
- whether this rule is public or not.java.lang.NullPointerException
java.lang.IllegalArgumentException
public java.lang.String toString()
toString
in class java.lang.Object
public void saveJSGF(java.net.URL url) throws java.net.URISyntaxException, java.io.IOException
url
- The URL to save this JSGFRuleGrammar to.java.net.URISyntaxException
- If there was a problem converting the given url to uri.java.io.IOException
- if an error occurs while saving or compiling the grammarpublic boolean isRuleChanged(java.lang.String ruleName)
public void setRuleChanged(java.lang.String ruleName, boolean changed)