Grammar Rule Name Referencing

ECMAScript expressions that are contained in tag elements generate semantic values that are associated with the Rule Variable of a rule element. Script expressions that are contained in a tag element can evaluate values and assign values to the Rule Variable of the tag element's containing rule element. This Rule Variable of the containing rule element is called the Grammar Rule Name (GRN) Rule Variable. Scripts evaluate or assign values to the GRN Rule Variable using GRN referencing.

A tag element can contain an individual script expression or a concatenated series of multiple script expressions. Script expressions cannot assign values to reserved words.

Creating Child Properties

Because the GRN Rule Variable is predefined as an object, direct child properties of it can be created without using a new Object() expression. Use out.PropName (where PropName is the name of the property) to identify properties of the GRN Rule Variable.

In the following example, the GRN Rule Variable of the rule named airport is predefined as an empty object. The script expressions contained in the tag elements create two properties (code and location) of the airport Rule Variable and assign values to these properties. The script expressions assign the value LHR to the code property, and the value England to the location property.

<rule id="airport">
  Heathrow
    <tag> out.code= "LHR"; </tag>
    <tag> out.location= "England"; </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:

<rule id="airport">
  Heathrow
    <tag> $.code= "LHR"; </tag>
    <tag> $.location= "England"; </tag>
</rule>

Creating Grandchild Properties

ECMAScript is not a strongly typed language, meaning that when a property is initialized, it is not predefined as a specific type. Instead, assigning a value to the property sets the property type to the same type as the assigned value. In the preceding example, because the location property is assigned a string value, the property type is string.

The way that type is set in ECMAScript has implications for creating grandchild properties. Before grandchild properties can be created, script writers must first initialize a child property of the type object to contain the grandchild properties. Initialize an object using a new Object() expression as shown in the following example.

<rule id="airport">
  Heathrow
    <tag> out.location= new Object(); </tag>
    <tag> out.location.country= "England"; </tag>
    <tag> out.location.city= "London"; </tag>
    <tag> out.location.elevation= "80 ft. MSL"; </tag>
</rule>

In this example, the script initializes the location property as an object. The grandchild properties country, city, and elevation are then initialized as direct properties of the child property location and assigned the values England, London, and 80 ft. MSL, respectively.

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

<rule id="airport">
  Heathrow
    <tag> $.location= new Object(); </tag>
    <tag> $.location.country= "England"; </tag>
    <tag> $.location.city= "London"; </tag>
    <tag> $.location.elevation= "80 ft. MSL"; </tag>
</rule>

Order of Assignment

The way that type is set in ECMAScript also has implications for the order in which script writers can assign values to the Rule Variable or its properties. The previous examples illustrate how a script writer can initialize the location property as a string or an object. Although the Rule Variable is predefined to be an object, the Rule Variable can also be changed to a different type through simple assignment. In the following example, the script assigns a string value to the Rule Variable, thus changing the type of the Rule Variable from an object to a string.

<rule id="airport">
  Heathrow
    <tag> out="A major airport near London"; </tag>
</rule>

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

<rule id="airport">
  Heathrow
    <tag> $="A major airport near London"; </tag>
</rule>

If the property type or the Rule Variable is changed, any values that already exist in the property or Rule Variable are lost. In the following example, the script initializes the code and location child properties and assigns the values LHR and England to them, respectively. However, in the next line, these properties and their values are destroyed when the Rule Variable is assigned a string value.

<rule id="airport">
  Heathrow
    <tag> out.code="LHR"; </tag>
    <tag> out.location="England"; </tag>
    <tag> out="A major airport near London"; </tag>
</rule>

In response to the utterance "Heathrow," this rule returns the semantic value "A major airport near London" and not the values LHR and England.

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

<rule id="airport">
  Heathrow
    <tag> $.code="LHR"; </tag>
    <tag> $.location="England"; </tag>
    <tag> $="A major airport near London"; </tag>
</rule>

See Also

Concepts

tag Element

Using the tag Element