3.20. grammar

Element typegrammar
Attributesfetchhint | fetchtimeout | maxage (2.0) | maxstale (2.0) | root (2.0) | scope | src | type | version (2.0) | weight (2.0) | xml:lang (2.0)
Parentschoice | field | form | link | record | transfer
ChildrenPCDATA | rule | possibly other proprietary grammar elements
DescriptionDefines the rules used to convert a user's utterances or user generated tones into string-valued variables that can be used in VoiceXML applications.

Language model



DTD

<!ELEMENT grammar (#PCDATA | rule)* >
<!ATTLIST grammar
  %grammar.attrs; >

Attributes

fetchhint : (prefetch | safe)

Indicates whether the interpreter may prefetch the destination document specified by this element's next attribute. A value of prefetch indicates the resource may be retrieved at the time the containing VoiceXML document is retrieved. A value of safe indicates that the resource specified by this element should not be prefetched, but should instead be retrieved at the time that the interpreter executes this element.

fetchtimeout : duration

The interval to wait for the content to be returned before throwing an error.badfetch event. If this attribute is not specified, the interpreter derives a value from the most locally scoped fetchtimeout property.

maxage : integer

Indicates the maximum allowable age of the fetched document in seconds. If the cached copy is older than the specified maxage, a new copy will be fetched when the interpreter executes this element. If this attribute is not specified, the interpreter derives a value from the most locally scoped maxage property. If no maxstale attribute is defined and it is impossible to fetch a new copy on the content the interpreter will throw an error.badfetch instead of using stale content.

maxstale : integer

Indicates that the interpreter may use stale content for this element as long as its age is no older than maxage plus the value of maxstale in seconds. If this attribute is not specified, the interpreter derives a value from the most locally scoped maxstale property.

mode : (voice | dtmf)

Provides a hint to the speech platform allowing it to optimize the use of recognizer resources. If this attribute is set to dtmf, the speech recognizer will not be activated.

root : IDREF

For inline grammar this specifies the root rule of this grammar element.

scope : (document | dialog)

Indicates the visibility of this grammar. If set to dialog, this grammar is only active in the dialog in which it is defined. If set to document, it is active in any dialog in the same document.

src : uri

The URI for the external source of this grammar element's contents.

type : CDATA

A MIME type for the grammar definition contained within this element. Typical values are application/grammar, application/x-jsgf, application/gsl, etc.

version : CDATA

Indicates the version of the grammar definition language used in the contents of this element.

weight : CDATA

A number defining the expected likelihood of this grammar element being activated by user interaction. The value of the weight attribute must be zero or a positive floating-point number. The default weight is 1.0. The weight attribute is useful for disambiguating a low-confidence recognition in the presence of multiple active grammars.

xml:lang : NMTOKEN

Defines the language dictionary to be used in this grammar (e.g. en-US for US English). If the language specified is not supported on the VoiceXML platform, the interpreter will throw an error.unsupported.language event.

Children

PCDATA

Contains non-XML grammar definitions, such as a GSL or ABNF grammar definition.

rule

Defines a grammar rule.

Examples

Example 3-22. A grammar defining acceptable answers for field favcolor
<?xml version="1.0" encoding="iso-8859-1"?>
<vxml version="2.0">
  <form id="test">
    <field name="favcolor">
      <prompt>What is your favorite color?</prompt>
      <grammar xml:lang="en-US" version="1.0" root="example1">
        <rule id="example1" scope="public">
          <one-of>
            <item><tag>'red'</tag>red</item>
            <item><tag>'green'</tag>green</item>
            <item><tag>'blue'</tag>blue</item>
            <item><tag>'red'</tag>burgundy</item>
            <item><tag>'blue'</tag>indigo</item>
          </one-of>
        </rule>
      </grammar>

      <filled> 
        <prompt>
          You said your favorite color is <value expr="favcolor"/>.
        </prompt>
      </filled>
    </field>
  </form>
</vxml>

Many of the interpreters in existence may use the older version of GRXML, where tag was an attribute of item. Example 3-23 shows the deprecated use of item.

Example 3-23. The old GRXML version
<?xml version="1.0" encoding="iso-8859-1"?>
<vxml version="2.0">
  <form id="test">
    <field name="favcolor">
      <prompt>What is your favorite color?</prompt>
      <grammar xml:lang="en-US" version="1.0" root="example1">
        <rule id="example1" scope="public">
          <one-of>
            <item tag="'red'">red</item>
            <item tag="'green'">green</item>
            <item tag="'blue'">blue</item>
            <item tag="'red'">burgundy</item>
            <item tag="'blue'">indigo</item>
          </one-of>
        </rule>
      </grammar>

      <filled> 
        <prompt>
          You said your favorite color is <value expr="favcolor"/>.
        </prompt>
      </filled>
    </field>
  </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.224.32.46