Browse
 
Tools
Rss Categories

Unexpected [object clsGeneral] in SI

Reference Number: AA-02055 Views: 992 0 Rating/ Voters

We sometimes see customers running into problems where they report something like [object clsGeneral] appearing in the results from a decode. 

When performing ASR decodes using either the SpeechPort directly (using our C or C++ APIs) or using our Media Server, the ASR decodes are performed and then the ECMAScript is processed to generate a corresponding Semantic Interpretation (SI) result.

Sometimes, if grammars are not correctly written, the ECMAScript processor does not know what type of object is being referenced, which can cause it to be initialized as a generic 'object' instead of what the user intended (perhaps an integer or a string). If this happens, the SI processor attempts to determine how best to represent the result being returned, but if the type is unclear, the [object clsGeneral] description is returned. This typically means that you need to clarify your intent for some variable, or in other words, more clearly define its type when it is first declared or used.

Valid ECMAScript types are described in the ECMAScript Language Specification.

A simple example of an ECMAScript problem is shown in the following grammar:

Problematic Grammar:

<?xml version="1.0" encoding="utf-8"?>
<grammar mode="voice" root="rootrule" tag-format="semantics/1.0" version="1.0"
   xml:lang="en-US" xmlns="http://www.w3.org/2001/06/grammar">

   <rule id="rootrule" scope="public">
      <item><ruleref uri="#otherrule"/><tag> out += rules.latest();</tag></item>
   </rule>

   <rule id="otherrule" scope="private">
      <one-of>
        <item>black<tag>out="You said black"</tag></item>
        <item>white<tag>out="You said white"</tag></item>
      </one-of>
   </rule>
</grammar>

  When attempting to use the above grammar, with the phrase white, you will see the following parse tree when viewed using our Speech Tuner's Grammar Editor, which should also be reflected in the API or MRCP results :

--->>  Parse Result 1 of 1  --->>

Number of Parses : 1

Parse Tree  1:

 $rootrule
   $otherrule
     "white"
     {!{out="You said white"}!}
   {!{ out += rules.latest();}!}

Number of Interpretations: 1
   Interpretation  1 : [object clsGeneral]You said white

As you can see, this [object clsGeneral] being returned in the interpretation string is unexpected, and can be confusing.

This is being caused by the ECMAScript not understanding the type of object that in being assigned to the out variable (remember that this may be an integer, a string or any other ECMAScript type you wish to use). Because of this, it assumes the object started out as a generic object instead of a string, which was the intent here.

Fortunately, the solution is fairly simple - the first time that you use the variable, make sure that you assign it, or initialize it as, an unambiguous type, whether that be an integer value, or as in the case here, a string as shown in the Correct Grammar example below where the simple solution is to initialize out as an empty string, thereby declaring it as an unambiguous type (string):

Correct Grammar:

<?xml version="1.0" encoding="utf-8"?>
<grammar mode="voice" root="rootrule" tag-format="semantics/1.0" version="1.0"
   xml:lang="en-US" xmlns="http://www.w3.org/2001/06/grammar">

   <rule id="rootrule" scope="public">
      <tag>out = "";</tag>
      <item><ruleref uri="#otherrule"/><tag> out += rules.latest();</tag></item>
   </rule>

   <rule id="otherrule" scope="private">
      <one-of>
        <item>black<tag>out="You said black"</tag></item>
        <item>white<tag>out="You said white"</tag></item>
      </one-of>
   </rule>
</grammar>

 ...this grammar can now be used to generate the expected SI output as shown here:

--->>  Parse Result 1 of 1  --->>

Number of Parses : 1

Parse Tree  1:

 $rootrule
   {!{out = "";}!}
   $otherrule
     "white"
     {!{out="You said white"}!}
   {!{ out += rules.latest();}!}

Number of Interpretations: 1
   Interpretation  1 : You said white

Note that the parse tree now shows that out is being correctly initialized here (this was not happening in the previous example). Please also be aware that this type of issue can happen with any ECMAScript variable, not only the special out variable.

The LumenVox Speech Tuner has a very powerful Grammar Editor built in, which allows grammars to be parsed and the results to be examined closely. We recommend using the Speech Tuner for testing all grammars, and specifically when SI errors such as this are suspected.



*Please note that LumenVox periodically updates the ECMAScript processor used internally by the ASR, so some behaviors may change over time as the ECMAScript specification changes.