Share via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Serialization of Multiple Rule Grammars (Microsoft.Speech)

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" xml:lang="en-US" mode="voice" root="destination"
  xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/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 Root Rule Variable (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 script expressions in the FlightDay rule do not affect the text content of the RRV. 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" xml:lang="en-US" mode = "voice" root="destination"
  xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0">

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

  <rule id="FlightDay">
    on
    <one-of>
      <item> Monday <tag> out._value=1; </tag></item>
      <item> Wednesday <tag> out._value=3; </tag></item>
      <item> Friday <tag> out._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 text="Fly me to Paris on Wednesday" utteranceConfidence="0.839" confidence="0.839" >
    Arriving at 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. The following grammar creates the weekDay property as an object of the root rule named destination. This causes weekDay to be represented as a separate node in the SML output. Although the following script shows weekDay being created as an unitialized object (out.weekDay = new Object();), this step is necessary only if weekDay itself has child properties of its own. The number of a weekday is assigned to the dayNumber property in the FlightDay rule. In the tag element associated with the ruleref element that targets the FlightDay rule, the weekDay property of the root rule is assigned the value of the referenced rule's dayNumber property. The expression rules.latest() represents the Rule Variable of the last-referenced rule, and the expression rules.latest().dayNumber represents the value of the dayNumber property on the Rule Variable of the last-referenced rule. Alternatively, the script expression out.weekDay=rules.FlightDay.dayNumber; produces the same results.

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

  <rule id="destination">
    <tag> out.weekDay=new Object(); </tag>
    Fly me to
    <one-of>
      <item> London <tag> out._value="Arriving at Heathrow"; </tag></item>
      <item> Paris <tag> out._value="Arriving at Orly"; </tag></item>
      <item> Berlin <tag> out._value="Arriving at Tegel"; </tag></item>
    </one-of>
    <ruleref uri="#FlightDay" /><tag> out.weekDay=rules.latest().dayNumber; </tag>
  </rule>

  <rule id="FlightDay">
    on
    <one-of>
      <item> Monday <tag> out.dayNumber=1; </tag></item>
      <item> Wednesday <tag> out.dayNumber=3; </tag></item>
      <item> Friday <tag> out.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 text="Fly me to Paris on Wednesday" utteranceConfidence="0.954" confidence="0.954" >
    Arriving at Orly
    <weekDay confidence="0.998"> 3 </weekDay>
</SML>

Note

This SML output illustrates serialization of a developer-defined property (the weekDay property). For more information, see Serialization of Developer-defined Rule Variable Properties (Microsoft.Speech).

See Also

Concepts

Semantic Markup Language Reference (Microsoft.Speech)

Using the tag Element (Microsoft.Speech)

tag Element (Microsoft.Speech)

ruleref Element (Microsoft.Speech)