A grammar consists of a list of rules.
A rule consists of a list of words and slots. For example: MY_RULE = "My name is $name" where "name" is a slot
Words, Nametags may be added or removed from slots. Upon adding and removing words, the grammar needs to be recompiled for the changes to take place. However, the original CompiledGrammar remains valid even if compilation never takes place.
Two types of slots exist: word slots and nametag slots
Data Fields | |
ESR_ReturnCode(* | compile )(struct SR_Grammar_t *self) |
ESR_ReturnCode(* | save )(struct SR_Grammar_t *self, const LCHAR *filename) |
ESR_ReturnCode(* | checkParse )(struct SR_Grammar_t *self, const LCHAR *transcription, SR_SemanticResult **result, size_t *resultCount) |
ESR_ReturnCode(* | addWordToSlot )(struct SR_Grammar_t *self, const LCHAR *slot, const LCHAR *word, const LCHAR *pronunciation, int weight, const LCHAR *tag) |
ESR_ReturnCode(* | resetAllSlots )(struct SR_Grammar_t *self) |
ESR_ReturnCode(* | addNametagToSlot )(struct SR_Grammar_t *self, const LCHAR *slot, const SR_Nametag *nametag, int weight, const LCHAR *tag) |
ESR_ReturnCode(* | setDispatchFunction )(struct SR_Grammar_t *self, const LCHAR *name, void *userData, SR_GrammarDispatchFunction function) |
ESR_ReturnCode(* | setParameter )(struct SR_Grammar_t *self, const LCHAR *key, void *value) |
ESR_ReturnCode(* | setSize_tParameter )(struct SR_Grammar_t *self, const LCHAR *key, size_t value) |
ESR_ReturnCode(* | getParameter )(struct SR_Grammar_t *self, const LCHAR *key, void **value) |
ESR_ReturnCode(* | getSize_tParameter )(struct SR_Grammar_t *self, const LCHAR *key, size_t *value) |
ESR_ReturnCode(* | setupVocabulary )(struct SR_Grammar_t *self, SR_Vocabulary *vocabulary) |
ESR_ReturnCode(* | setupRecognizer )(struct SR_Grammar_t *self, struct SR_Recognizer_t *recognizer) |
ESR_ReturnCode(* | unsetupRecognizer )(struct SR_Grammar_t *self) |
ESR_ReturnCode(* | destroy )(struct SR_Grammar_t *self) |
ESR_ReturnCode(* SR_Grammar::compile)(struct SR_Grammar_t *self) |
Compiles the grammar. In the case of a precompiled grammar, the function compiles those portions of the grammar that were dynamically added since the last compilation.
self | SR_Grammar handle |
ESR_ReturnCode(* SR_Grammar::save)(struct SR_Grammar_t *self, const LCHAR *filename) |
Saves a compiled grammar to a file.
self | SR_Grammar handle | |
filename | File to write grammar into |
ESR_ReturnCode(* SR_Grammar::checkParse)(struct SR_Grammar_t *self, const LCHAR *transcription, SR_SemanticResult **result, size_t *resultCount) |
Indicates if a transcription is a valid result of a Grammar rule.
self | SR_Grammar handle | |
transcription | Transcription value | |
result | [in/out] Array of semantic results to be populated | |
resultCount | [in/out] Length of result array |
ESR_ReturnCode(* SR_Grammar::addWordToSlot)(struct SR_Grammar_t *self, const LCHAR *slot, const LCHAR *word, const LCHAR *pronunciation, int weight, const LCHAR *tag) |
Adds word to rule slot.
self | SR_Grammar handle | |
slot | Slot name | |
word | Word to be added to the slot | |
pronunciation | Word pronunciation (optional). Pass NULL to omit. | |
weight | value to associate with word when adding to grammar; use to determine cost when parsing | |
tag | eScript semantic expression (tag) for the word |
ESR_ReturnCode(* SR_Grammar::resetAllSlots)(struct SR_Grammar_t *self) |
Removes all elements from all slots.
self | SR_Grammar handle |
ESR_ReturnCode(* SR_Grammar::addNametagToSlot)(struct SR_Grammar_t *self, const LCHAR *slot, const SR_Nametag *nametag, int weight, const LCHAR *tag) |
Adds nametag to rule slot.
self | SR_Grammar handle | |
slot | Slot name | |
nametag | Nametag to be added to the grammar | |
weight | value to associate with nametag when adding to grammar; use to determine cost when parsing | |
tag | eScript semantic expression (tag) for the nametag |
ESR_ReturnCode(* SR_Grammar::setDispatchFunction)(struct SR_Grammar_t *self, const LCHAR *name, void *userData, SR_GrammarDispatchFunction function) |
Sets user dispatch function (used for parsed callback, etc)
self | SR_Grammar handle | |
name | The name of the function which will trigger this callback when encountered during grammar parsing. | |
userData | The user data to be referenced in the callback implementation later on. | |
function | The dispatch function |
ESR_ReturnCode(* SR_Grammar::setParameter)(struct SR_Grammar_t *self, const LCHAR *key, void *value) |
Sets grammar parameter, overriding session defaults.
self | SR_Grammar handle | |
key | Parameter name | |
value | Parameter value |
ESR_ReturnCode(* SR_Grammar::setSize_tParameter)(struct SR_Grammar_t *self, const LCHAR *key, size_t value) |
Sets grammar parameters. This is a convenience function.
self | SR_Grammar handle | |
key | Parameter name | |
value | Parameter value |
ESR_ReturnCode(* SR_Grammar::getParameter)(struct SR_Grammar_t *self, const LCHAR *key, void **value) |
Returns grammar parameter value.
self | SR_Grammar handle | |
key | Parameter name | |
value | Parameter value |
ESR_ReturnCode(* SR_Grammar::getSize_tParameter)(struct SR_Grammar_t *self, const LCHAR *key, size_t *value) |
Return copy of unsigned int grammar parameter. This is a convenience function.
self | SR_Grammar handle | |
key | Parameter name | |
value | [out] Used to hold the parameter value | |
len | [in/out] Length of value argument. If the return code is ESR_BUFFER_OVERFLOW, the required length is returned in this variable. |
ESR_ReturnCode(* SR_Grammar::setupVocabulary)(struct SR_Grammar_t *self, SR_Vocabulary *vocabulary) |
Configures a vocabulary with the grammar.
self | SR_Grammar handle | |
vocabulary | The vocabulary to associate with |
ESR_ReturnCode(* SR_Grammar::setupRecognizer)(struct SR_Grammar_t *self, struct SR_Recognizer_t *recognizer) |
Associates Recognizer with the grammar.
self | SR_Grammar handle | |
recognizer | The recognizer to associate |
ESR_ReturnCode(* SR_Grammar::unsetupRecognizer)(struct SR_Grammar_t *self) |
Dissociates Recognizer with the grammar.
self | SR_Grammar handle |
ESR_ReturnCode(* SR_Grammar::destroy)(struct SR_Grammar_t *self) |
Returns AcousticModels associated with the grammar.
self | SR_Grammar handle | |
models | Associated models |
self | SR_Grammar handle |