Grammar Rule Reference Referencing (Microsoft.Speech)

Microsoft Speech Platform SDK 11

Collapse image Expand Image Copy image CopyHover image

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 rules.rulename, where rulename is the name of the referenced rule. In the following example, the script expression references the Rule Variable of the rule named airport and assigns the semantic value of this Rule Variable to the departfrom property of the Rule Variable of the rule named flight.

XML Copy imageCopy Code
<rule id="flight">
  <ruleref uri="#airport" /><tag> out.departfrom=rules.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 rule named airport and assigns the value "code" to the departFrom property of the Rule Variable for the rule named flight.

XML Copy imageCopy Code
<rule id="flight">
  <ruleref uri="#airport" />
  <tag> out.departFrom=rules.airport.code; </tag>
</rule>

You can also use an alternate syntax, created by Microsoft, to reference the Rule Variable of a rule element that is outside of the containing rule. To use this syntax, set tag-format="semantics-ms/1.0" in the grammar element. See Support for Semantic Markup.

Using the syntax of semantics-ms/1.0, the example above can be written as follows:

XML Copy imageCopy Code
<rule id="flight">
  <ruleref uri="#airport" />
  <tag> $.departFrom=$airport.code; </tag>
</rule>

The latest() Function for the Last-Referenced Rule

Developers can also use the latest() function on the rules object 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 latest() function notation instead of the GRR Rule Variable name.

XML Copy imageCopy Code
<rule id="flight">
  <ruleref uri="#airport" />
  <tag> out.departFrom=rules.latest().code; </tag>
</rule>

In the syntax of semantics-ms/1.0, the last ruleref element to be used in the expansion matching the utterance can be referred to by the shorthand symbol "$$". Using the syntax of semantics-ms/1.0, the example above can be written as follows:

XML Copy imageCopy Code
<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 Speech Recognition Grammar Specification (SRGS) Version 1.0, 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.

See Also