VoiceXML 2.1 Development GuideHome  |  Frameset Home

  tutorial Subgrammars  |  TOC  |  tutorial SubDialogs  

Tutorial: GSL Grammar Weighting

This tutorial is based on the things you accomplished in earlier Lessons. If you have not completed those tutorials, you'll need to go through them first.

In this Lesson, we will:

Step 1: creating our initial VoiceXML structure

From our previous tutorials, we now recognize the following structure as a normal starting point:


<?xml version="1.0" encoding="UTF-8"?>
<vxml version = "2.1">
  <meta name="maintainer" content="yourEmail@here.com"/>

</vxml>


Step 2: writing the prompts

The <form> and <field> tags should also be familiar by now. The grammar file will be called "dogs.grammar" and within that file, we reference a specific top-level grammar called "DOGS".


<?xml version="1.0" encoding="UTF-8"?>
<vxml version = "2.1">
<meta name="maintainer" content="yourEmail@here.com"/>

  <form id="dogs">
    <field name="dogbreed">

      <grammar src="dogs.grammar#DOGS" type="text/gsl"/>
      <prompt>
        What breed of dog do you have?
      </prompt>

      <noinput>
        <prompt>
          I did not hear you. Please try again.
        </prompt>
      <reprompt/>
      </noinput>

      <nomatch>
      <prompt>
        I did not understand. Please try again.
      </prompt>
      <reprompt/>
      </nomatch>

    </field>
    <filled>
      <prompt>
        You said
        <value expr="dogbreed" />
      </prompt>
    </filled>
  </form>
</vxml>


Now our document is ready for the grammar file.


Step 3: creating our grammar file

A grammar file is a separate file from our VoiceXML document, so open up a new window in your favorite text editor. First, write the top-level grammar that returns a value to the field "dogbreed" in the VoiceXML document. Again, we covered the concept of top -level and sub-level grammar rules in our last tutorial.


DOGS [
  BREEDS:d {<dogbreed $d>}
]


Now we fill in the utterances for our sub-level rule, "BREEDS". You should be familiar with this concept from our previous tutorial, but just to refresh your memory a bit, we will cover the basics of GSL syntax. Square brackets enclosing a possible utterance  indicates an "or" condition - if the grammar matches one of the values within the brackets, it will execute the return statement. Parentheses indicate an "and" condition - the grammar must match every word inside the parentheses to return a match. A question mark indicates an utterance value is entirely optional.

For example: