Share via


Serialization of Multiple Rule Grammars

  Microsoft Speech Technologies Homepage

The SML output for a grammar containing multiple rules, but with no semantic interpretation markup, is similar to the output for a grammar containing a single rule. However, SML output for unmarked, multiple rule grammars has no confidence attribute. The top-level SML node has only the text and utteranceConfidence attributes. The text content of the SML node is the text of the utterance. The following grammar contains two rules, with the root rule, destination, referencing the second rule, FlightDay.

<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar" 
 root="destination" xml:lang="en-US" tag-format="semantics-ms/1.0">

  <rule id="destination">
        Fly me to
        <one-of>
             <item>London</item>
             <item>Paris</item>
             <item>Berlin</item>
      </one-of>
    <ruleref uri="#FlightDay" />
  </rule>

  <rule id="FlightDay">
    on
    <one-of>
      <item>Monday</item>
      <item>Wednesday</item>
      <item>Friday</item>
    </one-of>
  </rule>

</grammar>

Using this grammar, the utterance, "Fly me to Paris on Wednesday," produces the following SML output:

<SML text="Fly me to Paris on Wednesday" utteranceConfidence="0.777">
  Fly me to Paris on Wednesday
</SML>

Assigning to the _value Property

If the RRV remains an object, assigning a value to the _value property of referenced rules has no effect on the text content of the SML node. For a grammar with multiple rules, the result is that the value of only the RRV's _value property becomes the text content of the SML node. This scenario is illustrated in the following script. The following grammar is identical to the previous grammar except for the addition of expressions in the second rule that assign a value to the _value property.

<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar" 
 root="destination" xml:lang="en-US" tag-format="semantics-ms/1.0">

  <rule id="destination">
    Fly me to
    <one-of>
      <item>London<tag>$._value="Arriving at Heathrow.";</tag></item>
      <item>Paris<tag>$._value="Arriving at Orly.";</tag></item>
      <item>Berlin<tag>$._value="Arriving at Tegel.";</tag></item>
    </one-of>
    <ruleref uri="#FlightDay" />
  </rule>

  <rule id="FlightDay">
    on
    <one-of>
      <item>Monday<tag>$._value=1;</tag></item>
      <item>Wednesday<tag>$._value=3;</tag></item>
      <item>Friday<tag>$._value=5;</tag></item>
    </one-of>
  </rule>

</grammar>

Using this grammar, the utterance, "Fly me to Paris on Wednesday," produces the following SML output:

<SML confidence="0.839" text="Fly me to Paris on Wednesday" utteranceConfidence="0.839">
    Arriving in Orly.
</SML>

Passing Values from Rule to Rule

To pass a value from one rule to another, create a property as an object of the referencing rule, and assign the value of the referenced rule's property to the referencing rule's object. In the following grammar, a property of the root rule destination is created as an object and named weekday. This causes weekday to be represented as a separate node in the SML output. The number of a weekday is assigned to the dayNumber property in the FlightDay rule. In the tag element associated with the ruleref to the FlightDay rule, the weekday property of the root rule is assigned the value of the referenced rule's dayNumber property. The double dollar symbol ("$$") represents the Rule Variable of the last-referenced rule.

<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar" 
 root="destination" xml:lang="en-US" tag-format="semantics-ms/1.0">

  <rule id="destination">
    <tag>$.weekday={}; </tag>
    Fly me to
    <one-of>
      <item>London<tag>$._value="Arriving at Heathrow.";</tag></item>
      <item>Paris<tag>$._value="Arriving at Orly.";</tag></item>
      <item>Berlin<tag>$._value="Arriving at Tegel.";</tag></item>
    </one-of>
    <ruleref uri="#FlightDay" /><tag>$.weekday=$$.dayNumber;</tag>
  </rule>

  <rule id="FlightDay">
    on
    <one-of>
      <item>Monday<tag>$.dayNumber=1;</tag></item>
      <item>Wednesday<tag>$.dayNumber=3;</tag></item>
      <item>Friday<tag>$.dayNumber=5;</tag></item>
    </one-of>
  </rule>

</grammar>

Using this grammar, the utterance, "Fly me to Paris on Wednesday," produces the following SML output:

<SML confidence="0.839" text="Fly me to Paris on Wednesday" utteranceConfidence="0.839">
    Arriving in Orly.
    <weekday>3</weekday>
</SML>

Note  This SML output illustrates serialization of a developer-defined property (the weekday property). See Serialization of Developer-defined Rule Variable Properties for more information.