Partilhar via


Referencing Grammar Rule Variables

  Microsoft Speech Technologies Homepage

This document briefly describes and illustrates the two different types of Rule Variable referencing.

Types of Rule Variable Referencing

Script expressions that are contained in tag elements generate semantic values that are associated with the Rule Variable of a rule element. There are two forms of reference to Rule Variables:

Use script expressions with GRN referencing to evaluate semantic values that are associated with the target Rule Variable, as well as to assign semantic values to the target Rule Variable. Use script expressions with GRR referencing only to evaluate semantic values that are associated with a target Rule Variable.

The required form of reference for a script expression depends on whether the expression refers to the Rule Variable of the containing rule element, or the Rule Variable of a rule element that is referenced by a ruleref element. Use GRN referencing when referencing the Rule Variable of the containing rule element. Use GRR referencing when referencing the Rule Variables of rule elements that are outside of the containing rule.

Use GRR references only to refer to the semantic values of Rule Variables that precede the GRR reference in the script execution order. Typically, the tag element containing the script with a GRR reference immediately follows the ruleref element that points to the <rule> holding the GRR reference's target Rule Variable.

Illustration of GRN Referencing vs. GRR Referencing

The following example illustrates the appropriate use of both forms of referencing. In this example, the rule with the id, time, contains references to two other rules named "ordinal" and "month" in lines 6 and 13, respectively. The time rule also contains a list with the items "Saturday" and "Sunday" in lines 9 and 10.

Lines 9 and 10 illustrate GRN referencing. In each of these lines, the item element contains a tag element. Script expressions contained in these tag elements assign values to the Weekday property of the Rule Variable belonging to the time rule.

Note  The script expression contained by the tag element on line 7 constructs the Weekday property as an empty object. This causes Weekday to be represented as a separate node in the Semantic Markup Language (SML) output, and allows for the possibility of creating grandchild properties.

Lines 6 and 13 illustrate GRR referencing. In line 6, a tag element immediately follows the ruleref element that points to the rule named ordinal. The script expression that is contained in the tag element in line 6 evaluates the semantic value associated with the ordinal rule. The script expression that is contained in the tag element in line 13 evaluates the semantic value associated with the month rule.

Note  The script expressions in a tag element can refer only to semantic values associated with the immediately preceding rule, and not any subsequently referenced rules. For example, the script expressions in the tag element in line 6 cannot refer to semantic values associated with the month rule since the semantic interpreter will have finished parsing the script expressions in line 6 before parsing the ruleref to month in line 13.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar" 
 root="time" xml:lang="en-US" tag-format="semantics-ms/1.0">
<rule id="time"> <example>the first Saturday in January</example>
  the
  <ruleref uri="#ordinal" /><tag>$.Ordinal=$$;</tag>
  <tag>$.Weekday={};</tag>
  <one-of>
    <item>Saturday<tag>$.Weekday._value=6; $.Weekday._attributes.dayname="Saturday";</tag></item>
    <item>Sunday<tag>$.Weekday._value=0; $.Weekday._attributes.dayname="Sunday";</tag></item>
  </one-of>
  in
  <ruleref uri="#month" /><tag>$.Month=$$;</tag>
</rule>
<rule id="ordinal">
    <one-of>
      <item> first <tag> $._value = 1 </tag> </item>
      <item> second <tag> $._value = 2 </tag> </item>
    </one-of> <tag> $._attributes.weekendnumber = $recognized.text; </tag>
</rule>
<rule id="month">
    <one-of>
      <item> January <tag> $._value = 1 </tag> </item>
      <item> February <tag> $._value = 2 </tag> </item>
    </one-of> <tag> $._attributes.monthname = $recognized.text; </tag>
</rule>
</grammar>

See Also