Grammar Rule Reference Referencing
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Application developers can use ECMAScript script expressions contained in tag elements to evaluate the semantic values associated with the Rule Variable of a rule element outside of the containing rule. The URI attribute of a ruleref element identifies a rule outside of the containing rule. This form of identification is called Grammar Rule Reference (GRR) referencing.
Identifying the GRR Rule Variable and Its Properties
The GRR Rule Variable is identified by $rulename, where rulename is the name of the referenced rule. In the following example, the script expression references the Rule Variable of the airport rule and assigns the semantic value of this Rule Variable to the departfrom property of the flight rule Rule Variable.
<rule id="flight">
<ruleref uri="#airport" /><tag>$.departfrom = $airport;</tag>
</rule>
If the GRR Rule Variable is an object, use $rulename.propname (where propname is the name of the property) to identify individual properties of the object. In the following example, the script expression references the code property of the GRR Rule Variable belonging to the airport rule and assigns the value of code to the departfrom property of the flight rule Rule Variable.
<rule id="flight">
<ruleref uri="#airport" /><tag>$.departfrom = $airport.code;</tag>
</rule>
$$ Variable for the Last-referenced Rule
Developers can also use the shorthand notation $$ in script expressions to reference the last ruleref element to be used in the expansion matching the utterance. This concept is illustrated in the following example. In this example, the preceding example is rewritten using the shorthand notation instead of the GRR Rule Variable name.
<rule id="flight">
<ruleref uri="#airport" /><tag>$.departfrom = $$.code;</tag>
</rule>
Remarks
- The GRR Rule Variable can only be evaluated; it cannot be assigned values.
- The special rule references, defined in the World Wide Web Consortium Speech Recognition Grammar Specification (W3C SRGS), cannot be evaluated in GRR references. These special rule references include NULL, VOID, and GARBAGE.
- A tag element containing script expressions with GRR references must appear after the ruleref element that the scripts reference.
- A script expression using GRR referencing generates semantic values only if the path that the speech recognizer follows through the grammar in response to an utterance includes the referenced rule. In the preceding examples, if a path through the airport rule is not followed, no semantic values are generated by the scripts that reference the airport rule.