ruleref Element

  Microsoft Speech Technologies Homepage

Specifies a reference to the rule to be imported. The referenced rule specifies the user input to be matched. This element is especially useful for reusing a component or off-the-shelf rules and grammars.

<ruleref
   uri = grammarUri
   special = (NULL | VOID | GARBAGE)
   type = media-type
   xml:lang = (en | en-US) >
</ruleref>

Attributes

  • uri
    Specifies the location of the rule to be referenced. A rule can be referenced using one of the following forms:

    • <ruleref uri="#rulename"/>: Specifies a reference to a local rule. Refers to a rule within the containing grammar.
    • <ruleref uri="grammarUri#rulename"/>: Specifies a reference to an external named rule of a grammar.
    • <ruleref uri="grammarUri"/>: Specifies a reference to the external root rule of a grammar.
    • <ruleref uri="grammarUri#rulename" type="media-type"/>: Specifies a reference to an external named rule of a grammar, with an associated media type.
    • <ruleref uri="grammarUri" type="media-type"/>: Specifies a reference to the external root rule of a grammar, with an associated media type.

    Optional. Either the uri or special attribute is required, but both cannot be used together.

  • special
    Specifies a reference to a rule that has specific interpretation and processing by a speech recognizer. A grammar must not redefine these special rulenames. The special rulenames are as follows:

    • NULL: Defines a rule that is automatically matched, meaning that the rule is matched without the user speaking any word.
    • VOID: Defines a rule that can never be spoken. Inserting VOID into a sequence automatically makes that sequence unspeakable.
    • GARBAGE: Defines a rule that may match any speech up until the next rule match, the content of the next token element, or until the end of spoken input.

    Optional. Either the special or uri attribute is required, but both cannot be used together.

  • type
    Optional. Specifies the media type of the grammar containing the reference. Consider using this attribute only as a last choice. For example, using this attribute may be appropriate when a grammar is retrieved through HTTP, and both of the following are true:

    • A Web server cannot be configured to indicate the correct media type
    • The grammar processor is unable to automatically detect the media type
  • xml:lang
    Optional. Specifies the language identifier, and optionally a country/region or other variation, for the content of the ruleref element on which it appears. The valid language identifiers are:

    • en for English
    • en-US for U.S. English

Remarks

The ruleref element is an empty element that allows authors to reuse grammars and to structure semantic properties into a hierarchy. Reusing grammars enables rule elements to reference other rule elements. For example, a grammar author can develop a series of grammars that support mathematic operations and numbers. The grammars can be redistributed using either a Web site or a compiled grammar. Other authors can use the distributed grammars, by adding a ruleref element to their own grammar referencing the appropriate file or resource location. By reusing existing rules, authors can more quickly build complex grammars.

All of the phrases that are specified inside of a single rule element are siblings (ordered by order of declaration in the recognized transition path). If these phrases are referenced by another rule, they become children of the rule that made the reference.

For example, the following grammar contains two rule elements, identified as rules "a" and "b." Rule "a" references rule "b." The three phrases contained in rule "b" are children of rule "a." All of the phrases contained in rule "b" are siblings.

<grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar"
 xml:lang="en-US" tag-format="semantics-ms/1.0" ...>
   <rule id="a">
      <ruleref uri="#b"/>
   </rule>
   
   <rule id="b">
      <one-of>
         <item>hello</item>
         <item>big</item>
         <item>world</item>
      </one-of>
   </rule>
</grammar>

Examples

Example 1

The following example demonstrates using a ruleref element to reference the local city rule in the containing grammar, cityList.grxml.

<!-- Grammar file "cityList.grxml" -->
   <grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar"
 xml:lang="en-US" tag-format="semantics-ms/1.0" ... >
      <rule id="city">
         <one-of>
            <item>Boston</item>
            <item>Madrid</item>
         </one-of>
      </rule>

      <rule id="location"> <ruleref uri="#city"/> </rule>
   </grammar>

Example 2

The following example demonstrates using a ruleref element contained in the grammar file, locations.grxml, to reference the root rule state in the external grammar file, stateList.grxml. In the grammar file, stateList.grxml, the value of the root attribute on the grammar element and the value of the id attribute on the rule element must be the same for this type of reference to work.

<!-- Grammar file "stateList.grxml" -->
   <grammar root="state" version="1.0" xmlns="http://www.w3.org/2001/06/grammar"
 xml:lang="en-US" tag-format="semantics-ms/1.0" ... >
      <rule id="state" scope="public"> ... </rule>
   </grammar>

<!-- Grammar file "locations.grxml" -->
   <grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar"
 xml:lang="en-US" tag-format="semantics-ms/1.0" ... >
      <rule ...>
         <ruleref uri="stateList.grxml"/>
      </rule>
   </grammar>

Example 3

The following example demonstrates using two ruleref elements, contained in the grammar file, customerInfo.grxml, to reference two external rules contained in the grammar file, restaurantInfo.grxml.

<!-- Grammar file "restaurantInfo.grxml" -->
   <grammar root="food" version="1.0" xmlns="http://www.w3.org/2001/06/grammar"
 xml:lang="en-US" tag-format="semantics-ms/1.0" ... >
      <rule id="food" scope="public">
            <one-of>
               <item>italian</item>
               <item>thai</item>
            </one-of>
      </rule>
      <rule id="location" scope="public"> 
            <one-of>
               <item>Bellevue</item>
               <item>Redmond</item>
               <item>Seattle</item>
            </one-of> 
      </rule>
   </grammar>

<!-- Grammar file "customerInfo.grxml" -->
      <grammar version="1.0" xmlns="http://www.w3.org/2001/06/grammar"
 xml:lang="en-US" tag-format="semantics-ms/1.0" ... >
         <rule ...>   
            <item repeat="0-1">I would like</item>
            <ruleref uri="restaurantInfo.grxml#food"/>
            <item repeat="0-1">in</item>
            <ruleref uri="restaurantInfo.grxml#location"/>
         </rule>
      </grammar>

See Also

Grammar XML | item Element