VoiceXML Developer Series: A Tour Through VoiceXML, Part VI
Grammar rules may contain other grammar rules
A grammar can be made up of other grammar rules, which allows us to create complex grammars by building larger grammar rules that are based on different rule subsets. For example, a grammar that matches a pizza order that's contained in a external grammar is below:
1 #JSGF V1.0 2 grammar phone; 3 <order> = <pizzaSize> <pizzaType> [pizza] [with] <topping>+; 4 <pizzaSize> = small | medium | large; 5 <pizzaType> = [hand] (tossed | stretched | thrown) 6 | [deep] (dish | chicago) 7 | stuffed [crust]; 8 <topping> = [and] pepperoni 9 | [and] olives 10 | [and] green peppers 11 | [and] mushrooms 12 | [and] pineapple 13 | [and] anchovies;
The grammar above contains 4 grammar rules. The <order> rule is composed of several other rules that exist in the same JSGF file. These are <pizzaStyle>, <pizzaType>, and <topping>. A sample utterance that would match this grammar is listed below:
I would like to order a small deep dish pizza with olives, and pepperoni, and anchovies.
Below is a simple VoiceXML fragment that uses the external JSGF grammar listed above.
1 <?xml version="1.0"?> 2 <vxml version="1.0"> 3 <form id="pizzaOrder"> 4 <block>Hello, thank you for calling Joe's Pizza palace. May I take your order?</block> 5 <field name="order"> 6 <grammar src="pizzaOrder.jsgf" type="application/x-jsgf" /> 7 </field> 8 </form> 9 </vxml>
The JSGF format is, in my personal opinion, easier to work with for developing simple grammars. However, I prefer GSL, because it is more widely supported and contains more features for building large and complex grammars. That's not to say that you can't do the same with JSGF. IBM's platform is more than capable of performing the same interactions as a platform from Nuance or Speechworks. In the next
About Jonathan Eisenzopf
Jonathan is a member of the Ferrum Group, LLC based in Reston, Virginia that specializes in Voice Web consulting and training. He has also written articles for other online and print publications including WebReference.com and WDVL.com. Feel free to send an email to firstname.lastname@example.org regarding questions or comments about the VoiceXML Developer series, or for more information about training and consulting services.
Page 2 of 2