swirec_grammar_script

A grammar script to be invoked on the root rule of each n-best result.

Value

Any wchar string

Default

(empty)

How to set

Shown in precedence order (see Rules of parameter precedence):

Set in the browser, using the Vendor-Specific-Parameters header in a RECOGNIZE or SET-PARAMS method.

In a parameter grammar.

Usage

Perform computations on keys and values before Recognizer returns final results. A common use is to avoid repeating a mistake in a second recognition attempt. Another use is to remove an item from the vocabulary because it is not relevant for the current caller. (For example, consider a banking application where the customer has a checking and savings account, but not an investment account. The script could eliminate "invest" from the command vocabulary.)

This parameter specifies such a script when the associated grammar uses swi syntax; when the grammar uses literal or script syntax, use swirec_grammar_script_sisr instead.

The script must handle (perhaps, by ignoring) entries that result from unexpected grammars. For example, if a stock quotation grammar and a command grammar are activated in parallel, and the script tests the value of a stock name key, the script must not fail when a command word appears in the n-best list (and the command grammar does not contain the key being tested).

In addition to writing scripts to perform specific computations for specific grammars, you can also write general-purpose scripts. A common use is to avoid repeating a mistake during a recognition retry: by preventing the recognition of an item that has previously been rejected by the caller. Consider recognitions of the following grammar:

<?xml version="1.0" encoding="ISO8859-1" ?>
<grammar mode="speech" xml:lang="en-US" version="1.0" root="ROOT" xmlns="http://www.w3.org/2001/06/grammar">
<rule id="ROOT" scope="public">
<one-of>
<item tag="city='boston'">boston</item>
<item tag="city='austin'">austin</item>
<item tag="city='chicago'">chicago</item>
<item tag="city='new_york'">new_york</item>
</one-of>
</rule>
</grammar>

If the caller answers "no" to a confirmation of "austin", then "austin" needs to be removed from consideration in the second recognition attempt of this grammar. Rather than generating a new grammar without the choice "austin," you could add a script to remove "austin" if it appears in the n-best list. To support this, set swirec_grammar_script as follows:

"if (city == 'austin') SWI_disallow =1;"

Browsers usually set this parameter in a RECOGNIZE request, and the parameter automatically reverts to the previous value after the recognition event. (The SET-PARAMS method defines the value for the duration of the session, or until another SET-PARAMS call.)

Vendor-Specific-Parameters: swirec_grammar_script="if (city == 'austin') SWI_disallow =1;"