3.46. rule

Element typerule
Attributesid | scope
Parentsgrammar
Childrenexample | item | one-of | ruleref | tag | token
DescriptionDefines a grammar rule by associating a rule expansion with an identifier.

DTD

<!ELEMENT rule (%rule-expansion; | example | tag)* >
<!ATTLIST rule
  id    ID                 #REQUIRED
  scope (private | public) "private" >

Language model



Attributes

id : ID

A unique identifier for this rule. It is used to refer to this rule from ruleref or grammar elements.

scope : (public | private) = private

Indicates the visibility of this rule. If this attribute is set to private, this rule is only visible within the grammar element in which it is defined. If it is set to public, the rule can be imported and accessed by rules defined elsewhere.

Children

A rule expansion that represents this rule.

Examples

The form-level grammar element defines two rules, flight and city. The flight rule is designed to match phrases like "I'd like to fly from Toronto to London" or "to London from Toronto." It uses the city rule to recognize the specific city names like "London" and "Toronto." Some older interpreters might not understand the repeat attribute on item. In this situation you would use the count attribute as explained in 3.24, “item,”.

Example 3-57. A GRXML rule for scheduling a flight
<?xml version="1.0" encoding="iso-8859-1"?>
<vxml version="2.0">
  <form id="airlines">
    <initial name="itinerary">
      Where would you like to fly?
      <catch event="nomatch noinput">
        <prompt>I didn't get that.</prompt>
        <assign name="itinerary" expr="true"/>
        <reprompt/>
      </catch>   
    </initial>

    <grammar xml:lang="en-US" version="1.0" root="flight">
      <rule id="flight" scope="public">
        <one-of>
          <item>
            <item repeat="0-1">I'd like to fly</item> from 
            <ruleref uri="#city"> 
              <tag>depart=city.returnvalue;</tag>
            </ruleref>  
            to 
            <ruleref uri="#city"> 
              <tag>arrive=city.returnvalue;</tag>
            </ruleref>
          </item>

          <item>
            <item repeat="0-1">I'd like to fly</item>
            to 
            <ruleref uri="#city"> 
              <tag>arrive=city.returnvalue;</tag>
            </ruleref>  
            from 
            <ruleref uri="#city"> 
              <tag>depart=city.returnvalue;</tag>
            </ruleref>
          </item>

        </one-of>
      </rule>

      <rule id="city" scope="public">
        <one-of>
          <item> <tag>returnvalue='New York';</tag>New York</item>
          <item>
            <tag>returnvalue='Los Angeles';</tag>Los Angeles
          </item>
          <item> <tag>returnvalue='Los Angeles';</tag>L A</item>
          <item> <tag>returnvalue='Toronto';</tag>Toronto</item>
          <item> <tag>returnvalue='London';</tag>London</item>
          <item> <tag>returnvalue='Paris';</tag>Paris</item>
        </one-of>  
      </rule>
    </grammar>

    <field name="depart">
    </field>

    <field name="arrive">
    </field>

    <filled>
      <prompt>
        I have you flying from 
        <value expr="depart"/> to <value expr="arrive"/>.
      </prompt>
    </filled>
  </form>
</vxml>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.25.26