Getting key values in results

To retrieve the current values of special SWI_ keys, get the recognition results as returned by your environment or voice platform.

Note: Nuance Recognizer supports all keys. Dragon Voice supports SWI_literal, SWI_spoken, SWI_meaning, SWI_utteranceSNR.

Default keys in recognition results

These keys appear in recognition results by default:

For all other keys, use swirec_extra_nbest_keys to them to recognition results.

Keys set in application URIs for ECMAScript use

These keys are set by an application and can be used by ECMAScript in grammar files, but are not available directly in the recognition result.

Only one SWI_ key appears in this category, but it is a significant one which we have already used in our ECMAScript examples: SWI_vars.

Keys available during recognition to ECMAScript scripts

These keys are returned by Recognizer, and are available during recognition for use by ECMAScript scripts in the loaded grammars.

As in the case of SWI_vars, we have already seen these two keys in our examples (see Using parseTool to verify ECMAScript).

Keys set to control n-best processing and confidence scoring

Set these keys in grammars to control and improve n-best processing and confidence scoring.

Nuance Recognizer supports these keys. Dragon Voice does not.

Keys set by Recognizer and available in recognition result

The Recognizer sets these keys during recognition, and returns them in the recognition result. Unless noted otherwise, these keys are not accessible within a grammar.

Using SWI_ keys in grammars with W3C script syntax

To provide access to SWI_keys in grammars written with W3C script syntax, Nuance allows the use of the ECMAScript variables SWI and SWIrules.

Like the out variable, a SWI variable is an object that is automatically created before execution of the first semantic script in a rule. Your scripts inside the rule can set SWI_keys on the SWI object.

For example:

SWI.SWI_meaning = "blue"

Like the rules variable, you can use the SWIrules variable to access any of the SWI_keys that were set on the SWI object of a previously referenced rule:

  • SWIrules.rulename holds the value of the SWI variable of a referenced rule.
  • SWIrules.latest() holds the value of the SWI variable of the last referenced rule.

As with swi syntax grammars, SWI_confidence, SWI_literal and SWI_spoken are set automatically for every rule. Since they are returned only after a rule has resulted in a positive recognition, you can only use them in a context outside the invoked rule in your GrXML file.

For example:

<rule id="myrule">
    <ruleref uri="#subrule" />
    <tag>
        out.mytag=SWIrules.subrule.SWI_literal;
        out.myconf=SWIrules.subrule.SWI_confidence;
        out.myspoken=SWIrules.subrule.SWI_spoken
    </tag>
</rule>
<rule id="subrule">
    ... <!-- Defines the words to be recognized -->
</rule>

For comparison, the following example is not correct, because SWI.SWI_literal, SWI.SWI_confidence and SWI.SWI_spoken are being invoked within myrule:

<rule id="myrule">
    yyy
    <tag>
        out.x=SWI.SWI_literal;
        out.y=SWI.SWI_confidence;
        out.z=SWI.SWI_spoken;
    </tag>
</rule>

The following grammar illustrates the use of SWI and SWIrules in W3C script syntax:

<?xml version='1.0' encoding='UTF-8'?>
<grammar xml:lang="en-US" version="1.0" root="ROOT"
  tag-format="semantics/1.0"
  xmlns="http://www.w3.org/2001/06/grammar">
 <rule id="A">
  indigo 
  <tag> 
   SWI.SWI_meaning = "blue"; 
   out = "lovely" 
  </tag> 
 </rule>
 <rule id="ROOT">
  <ruleref uri="#A"/>
  elephant
  <tag> 
   out.animal = "weird";
   out.other = rules.A.out;
   out.color = SWIrules.A.SWI_literal;
   SWI.SWI_meaning = SWIrules.latest().SWI_meaning;
   SWI.SWI_decoy = 1; 
  </tag>
 </rule>
</grammar>

The XML result for a parse of “indigo elephant” would contain the following semantic elements (here shown in the application/x-vnd.speechworks.emma+xml format):

...
 <instance>
  <animal confidence="98">weird</animal>
  <other confidence="98">lovely</other>
  <color confidence="98">indigo</color>
  <SWI_meaning>blue</SWI_meaning>
  <SWI_decoy>1</SWI_decoy>
  <SWI_literal>Indigo elephant</SWI_literal>
 </instance>
...

Note: This example assumes that swirec_extra_nbest_keys is set to SWI_meaning, SWI_decoy and SWI_literal.