Browse
 
Tools
Rss Categories

Working with Grammars

Reference Number: AA-00605 Views: 11610 0 Rating/ Voters

When a grammar is loaded, it is compiled into a format usable by the Engine. But to use the grammar for a decode you must activate it. You may activate multiple grammars for a single decode; the results will contain which grammar was matched.

Because loading a grammar takes longer than activating it, it is often desirable to load all the grammars you will need for an application in advance, and activate and deactivate grammars as needed for a given decode (loading grammars will be faster the second time by default because the Engine will cache grammars). It is good practice to only activate the grammars you need for a specific decode, as having extra vocabulary items in the active grammar can reduce recognition accuracy.

A good idea is to build different grammars for specific uses in your application. For instance, when building a telephony IVR, you might use a different grammar for each prompt. You could load all the grammars into a port at the start of the application, and as the user moves through prompts you could activate the grammar for a specific prompt and then deactivate it when the user moves to the next menu.

When you ask the Engine to perform a decode, you will have to specify the grammar to be used (this is mainly when using the older concept/phrase grammar type). When using SRGS grammars, the collection of all the active grammars is called the active grammar set; to decode against this set you provide LV_ACTIVE_GRAMMAR_SET as the grammar name.

C Code

/*
* Activates the "yes_no" grammar that was loaded above.
* Activate searches for a grammar named "yes_no" in its port,
* then searches the global space if it can't find it.
*/
LV_SRE_ActivateGrammar(hport, "yes_no");


C++ Code

port.ActivateGrammar("yes_no");

Deactivating Grammars

In the same way that you can activate grammars, you can deactivate grammars.

C Code

LV_SRE_DeactivateGrammar(hport, "yes_no");

LV_SRE_DeactivateGrammars(hport);


C++ Code

port.DeactivateGrammar("yes_no");

port.DeactivateGrammars();

See Also