Working with SI Script Video



  • Semantic Interpretation, what is it and why use it when building your speech recognition application? In this series, Stephen Keller covers detailed examples of the process of determining what callers mean, not what they say. Also included is a discussion of Semantic Interpretation for Grammars and DTMF.
  • RUNTIME 17:20


Video Transcription

Working with SI Script

In this video, we'll cover SI Script. It's the alternative to string literals, the tag format we discussed in Part 2.


SI Script is an implementation of what's called ECMAScript. This is a W3C scripting language that you probably best know as JavaScript. The information inside the tags is ECMAScript. This gives you powerful, flexible commands because you have this whole scripting language available to you.

In order to use SI Script in your grammars, you need a tag-format declaration: semantics/1.0.2006. Like our declaration for string literals, this is a little different than what the W3 spec would say, because we maintain backwards compatibility with older versions of the SISR spec.

Writing to the Rule Variable

The main thing we want to do is access rule variables. The first thing we want to do is access the rule variable for the rule you're currently in. The current rule variable is identified by "out". What you'll be doing in SI Script is assigning a value to "out". Unlike in string variables, rule variables will always be initialized as empty objects. With SI Script as in JavaScript, you can declare variables and properties on the fly. You can modify the property of a rule variable by out.propertyname.


I'm sure you're familiar with this example by now, but we've made two changes here. The first is we've added our tag-format declaration at the top, and the second is that we've done some SISR using SI Script. We have curly braces for our SI tag: {out=100}.

#ABNF 1.0 UTF-8;
language en-US;
mode voice;
tag-format ;

root $name;

&robertsmith = (Robert|bob) [smith]

$name = $robertsmith;


  • Caller says "Bob"
  • The $robertsmith rule is matched
  • Its rule variable is assigned a value of 100
    • Turns it into a simple integer instead of an object
  • Root rule inherits last matched rule's variable

Object Example

$robertsmith = (robert | bob) [smith]

	{out.extension = 100; = "Robert Smith"};


  • Caller says "Bob"
  • Result is an object with two properties:
    extension : 100,
    name : "Robert Smith"

Rule Expansion

  • Rules are expanded such that any matched rule they reference become children
  • Builds a parse tree for that parse:
    $ruleA = $ruleB;
    • ruleB becomes part of ruleA for the parse, acting as ruleA's child
    • <ruleref uri="#rulename"/> in GrXML

Rule Visibility

Only the rule variables of a rule's children are visible to that rule. Grandchildren are not visible to the grandparent. For example:

$ruleA = $ruleB;

  • Can access rule variables for $ruleB from $ruleA
  • Cannot access $ruleC variables because it is not a child of $ruleA

Accessing Other Rule Variables

To access another rule's variable, that rule must be visible to the current rule.


  • The rule variable for the rule called "rulename"
    • rules.ruleB is the rule variable for $ruleB
    • rules.rulename.propertyname is also valid


  • The rule variable of the last matched rule
    • rules.latest().propertyname is also valid

Date Capture Grammar

root $date;

$date = $month $day $year;

$month = January {out = "01/"} | February
	{out = "02/"} | March {out = "03/"};

$day = first {out = "01/"} | second
	{out = "02/"} | third {out = "03/"};

$year = Two thousand one {out = "2001"} | 
Two thousand two {out = "2002"} |
Two thousand three {out = "2003"};

So now when the caller says "January First Two Thousand One", the result is "01/01/2001".

That was using the rules.rulename method. When would you want to use the rules.latest method?

Example of rules.latest

There are some instances when you can't be sure what order rules were spoken in. In the last example we were only going to accept month/ day /year. But let's say you want to collect a string of digits, and you don't know which digits are going to come first.

root &binary;

$binary = {out = ''} (($zero | $one) 
{out + = rules.latest()})<1->;

$zero = (zero | o) {out = 0};
$one = one {out = 1}; 

When the caller says "Zero one zero one", the result is "0101".

With SI Script

  • Format output
  • Combine multiple variables

In the next video, we'll cover advanced SI Script, specifically adding application-type logic to your grammar through SISR.

© 2018 LumenVox, LLC. All rights reserved.