VoiceXML Forum Community Message Board


Post New Topic  Post A Reply
my profile | register | search | faq | forum home
  next oldest topic   next newest topic
» VoiceXML Forum Community Message Board   » Newbies   » Mapping response to a value

 - UBBFriend: Email this page to someone!    
Author Topic: Mapping response to a value
Thomas McCarthy
Junior Member
Member # 3580

Rate Member
Icon 1 posted May 30, 2006 01:44 PM      Profile for Thomas McCarthy     Send New Private Message       Edit/Delete Post   Reply With Quote 
Is there a way to map a response to a certain value? For instance, if the user says yes sure or yeah I'd like to put 1 in the database. If the user says no, nope, nah I'd put 0.

I'm unsure of how to map yes or no to a 0 or 1 value though. What would be the easiest way to do this? I typically work in jsps, so I had considered matching strings, but had thought there might be an easier solution you can point me to.

As it is I use an if/then statement in the vxml page to pass each response to a yes or no jsp in which the proper response in logged, but that gets overly complicated quickly.

Posts: 1 | Registered: May 2006  |  IP: Logged
mheadd
Member
Member # 3181

Member Rated:
4
Icon 1 posted May 31, 2006 02:49 PM      Profile for mheadd   Author's Homepage   Email mheadd   Send New Private Message       Edit/Delete Post   Reply With Quote 
There are a couple of option open to you if all you are using is a simple yes/no grammar.

Option 1 = use the builtin "boolean" grammar type. By specifying a field type of "boolean", an implicit grammar is created that should cover affirmative or negative responses for whataver language is being used. A boolean field returns a JavaScript string based on what the user says (e.g., yes='true' or no='false'). You can convert this to a 1 or 0 using a simple if/else construct and a predefnied variable.

code:
  

<var name="convert" expr="0"/>

...

<field name="F_1" type="boolean">
<prompt>Do you think VoiceXML rocks?</prompt>
<filled>

<!-- If the user says yes, then the expression in the "cond" attribute will evaluate to true -->
<if cond="F_1">
<assign name="convert" expr="1"/>
</if>

<!-- If the preceding if statement did not execute, then expression in the cond attribute evaluated to false. User said no, so we keep our original value of 0 -->
<submit next="mypage.jsp" namelist="convert"/>

</filled>
</field>

Option 2 = you can use the <tag> element with a custom yes/no grammar to return a 1 or a 0. (Check your platform vendor's documentation on this element, as there is some variation.)

code:
<!-- In your VoiceXML document, reference the yes/no grammar -->
<field name="F_1">
<grammar src="yesno.grxml"/>
...


<!-- Contents of yesno.grxml file -->
<?xml version = "1.0"?>
<grammar xml:lang="en-US" version="1.0" root="R_1" type="application/srgs+xml" xmlns="http://www.w3.org/2001/06/grammar">
<rule id="R_1">
<one-of>
<item>yes <tag>F_1=1;</tag> </item>
<item>yeah <tag>F_1=1;</tag> </item>
<item>hells yeah <tag>F_1=1;</tag> </item>
<item>yur damn skippy <tag>F_1=1;</tag> </item>
<item>no <tag>F_1=0;</tag> </item>
<item>nope <tag>F_1=0;</tag> </item>
<item>no way <tag>F_1=0';</tag> </item>
<item>hells no <tag>F_1=0;</tag> </item>
</one-of>
</rule>
</grammar>

This has the effect of filling the field named "F_1" with the value specified in the <tag> when one of the grammar items is recognized. A few good links to get you started follow:

BeVocal Cafe

Voxeo Community

Hope this helps.

[ May 31, 2006, 02:50 PM: Message edited by: mheadd ]

--------------------
Mark
VoiceinGov.org
http://www.voiceingov.org

Posts: 55 | Registered: Jun 2005  |  IP: Logged


All times are Eastern  
Post New Topic  Post A Reply Close Topic    Move Topic    Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:

Contact Us | VoiceXML Forum



Powered by Infopop Corporation
UBB.classicTM 6.3.1.2