VoiceXML 2.1 Development Guide Home  |  Frameset Home


<tag>  element


The tag element is another SRGS addition to VWS2.0 that allows the developer to specify an arbitrary string that is used for semantic interpretation. Essentially, what the tag element does is to define the returned value from a valid user utterance.


usage

<tag />


attributes

none


shadow variables

none


parents

<item>   <rule>


children

none


code samples

<TagCode.vxml>
<?xml version="1.0" encoding="UTF-8"?>

<vxml version = "2.1" xmlns="http://www.w3.org/2001/06/grammar">

<meta name="author" content="Matthew Henry"/>
<meta name="copyright" content="2005 voxeo corporation"/>
<meta name="maintainer" content="YOUR_EMAIL@HERE.COM"/>


<form id="F1">

  <field name="F_1">
    <prompt>
      What are the chances that Saddam Hussein will land a Saturday
morning television gig?
    </prompt>

    <grammar src="MyTagGrammar.xml#MYRULE" type="application/grammar-xml"/>

    <filled>
      <prompt>
        Well, you said <value expr="F_1"/>.
    </prompt>

  </filled>

  </field>

</form>

</vxml>


<MyTagGrammar.xml>
<?xml version= "1.0"?>

<grammar xmlns="http://www.w3.org/2001/06/grammar"
          xml:lang="en-US" root = "MYRULE">

  <rule id="MYRULE" scope="public">
    <one-of>
      <item> pretty high <tag>out.F_1= "pretty high"</tag></item>
      <item> no frigging way<tag>out.F_1= "no frigging way"</tag></item>
    </one-of>
  </rule>

</grammar>



additional links

W3C SRGS 1.0 Specification


  ANNOTATIONS: EXISTING POSTS
moshe
6/9/2004 8:01 AM (EDT)
Use of the <tag> command is explained in the Nuance grammar spec, http://community.voxeo.com/vxml/docs/nuance20/grammar.pdf, in the chapter called "Natural Language Understanding." The spec explains the slot-filling command ("<slot value>") as well as the use of the "return" function, the assign function, etc.

All of these are extensions to the W3C spec, which merely states that <tag> contains CDATA.
awirtz
1/21/2005 9:12 PM (EST)
The nuance code inside a <tag> block will be executed when the element immediately preceding the <tag> is matched.  This means that in the following example the <tag> block will only actually be evaluated if "enough" is matched.

<grammar xmlns="http://www.w3.org/2001/06/grammar"
          xml:lang="en-US" root = "MYRULE">
  <rule id="MYRULE" scope="public">
    <item>
      high
      <item repeat="0-1">enough</item>
      <tag> <![CDATA[  <F_1 "fair">  ]]>  </tag>
    </item>
  </rule>
</grammar>

This will operate as expected though:

<grammar xmlns="http://www.w3.org/2001/06/grammar"
          xml:lang="en-US" root = "MYRULE">
  <rule id="MYRULE" scope="public">
    <item>
      <item>
        high
        <item repeat="0-1">enough</item>
      </item>
      <tag> <![CDATA[  <F_1 "fair">  ]]>  </tag>
    </item>
  </rule>
</grammar>

Debugging this case is further complicated by the fact that if no explicit slot assignment command is executed, the slot will be filled with the literal spoken text instead.
awirtz
1/21/2005 10:18 PM (EST)
Here is a quick list of available Nuance functions (Please correct me if I got something wrong.  Many of these details are learned from experimentation, as the Nuance documentation is not always very clear.):

< slot $n >

Sets the value of the slot named "slot" in the parent form to the value specified by $n.  ($n can be a variable, a literal, or a function)  If a field-level grammar is matched but does not explicitly populate a slot, the entire literal match for the utterance will be placed in the slot.

return( $n )

Sets the special variable $return in the calling rule to the value specified.  Note that not returning any value from a subgrammar will leave the value of $return in the caller unchanged. (thus a caller could call a subgrammar which returns a value, and then one which does not, and at the end, the special variable $return would still contain the first subgrammar's return value.)
It should also be noted that calling return( $n ) from a root grammar will not populate the form slot; that must be done explicitly by name using the angle bracket operators.

assign( variable $n )

Stores the specified value in a local variable named "variable".  The initial $ should be omitted from the variable name.  As usual, $n can be a variable, literal, or function, and still needs to have an initial $ if it is a variable.

add( $a $b )

Evaluates to the sum of $a and $b.  $a and $b may be variables, literals, or functions.  If either is an unpopulated variable, it will be treated as though the variable was 0.

sub( $a $b )

Evaluates to $a minus $b.  $a and $b may be variables, literals, or functions.  If either is unpopulated, a value of 0 is assumed.

mul( $a $b )

Evaluates to the product of $a and $b.  $a and $b may be variables, literals, or functions.  If either is unpopulated, a value of 1 is assumed.

div( $a $b )

Evaluates to the integer quotient of $a over $b.  This value will be truncated (not rounded) to  form an integer. $a and $b may be variables, literals, or functions.  If $a is unpopulated, 0 is assumed.  If $b is unpopulated, 1 is assumed.

neg( $n )

Evaluates to the negative of $n.  Essentially equivalent to mul( $n -1 ).  $n may be a variable, literal, or function.  If $n is unpopulated, 0 is assumed.

strcat( $a $b )

Evaluates to the concatenation of $a and $b. If $a or $b is unpopulated, the empty string is assumed.

-----

In addition to these functions, there are also 2 special variables, $return and $string.

$return

This variable holds the last value returned from a subgrammar using the return( $n ) function.

$string

This variable holds the literal value matched by the block immediately preceding the <tag>.
safarishane
3/27/2006 8:00 PM (EST)
Is there a way to use <tag></tag> with explicity stateing which slot to fill?

For example, a simple grammar can be reused by any field:


<rule id="CONFIRMATION" scope="public">
<one-of>
<item>
  <one-of>
    <item> yes </item>
    <item> yup </item>
    <item> duh </item>
  </one-of>
</item>
<item>
  <one-of>
    <item> no </item>
    <item> nope </item>
    <item> negative ghostrider </item>
  </one-of>
</item>
</one-of>
</rule>

The utterance will fill any field name.  But, I would like all utterances to return a simple true/false:

<rule id="CONFIRMATION" scope="public">
<one-of>
<item>
  <one-of>
    <item> yes </item>
    <item> yup </item>
    <item> duh </item>
  </one-of>
  <tag>true</tag>
</item>

<item>
  <one-of>
    <item> no </item>
    <item> nope </item>
    <item> negative ghostrider </item>
  </one-of>
  <tag>false</tag>
</item>
</one-of>
</rule>

In this case, I'm getting a compile error, which I can make go away by explicitly specifing the slot name as demonstrated above.  What if I don't know the slot name ahead of time?  Can I still use <tag/>?

Thanks,
Shane
kevinlim
3/27/2006 8:53 PM (EST)
Shane, here is a sample from our gurus that may illustrate the technique you're looking for:

I'll let the code do the talking


<?xml version= "1.0"?>




<grammar xmlns="http://www.w3.org/2001/06/grammar"" xml:lang="en-US"
root="INTRO">



<!-- ********** -->


<rule id="INTRO">

<one-of>
    <item>

      <one-of>
        <item>
    yeah
        </item>

        <item>
    yup
        </item>

        <item>
    sure
        </item>

        <item>
    okay
        </item>

        <item>
    right
        </item>

        <item>
    yes
        </item>


        <item>
    yes please
        </item>

        <item>
    dtmf-1
        </item>

      </one-of>
    <tag> <![CDATA[  <MySlot "yes">  ]]>  </tag>
    </item>



</one-of>

    </rule>

</grammar>



Best,
Kevin
Voxeo Extreme Support
safarishane
3/28/2006 10:29 AM (EST)
Kevin, thanks, but I guess I mistyped my question.  Actually, I'm looking for how to do it "without" explicitly setting the slot to fill in <tag/>. 

(I said "with", but meant "without". Arn't you people psychic?)

Thanks,
Shane
MattHenry
3/28/2006 4:51 PM (EST)


If you want to fill an 'anonymous' slot, then I'd think you'd want to use the "return" command:


      <tag> <![CDATA[  <return ("yes")>  ]]>  </tag>


~Matt
safarishane
3/29/2006 12:14 PM (EST)
Mr Henry,

Thanks, but I don't thing return works for root rules, only rule references.  I pulled this example off the semantic interpretation spec: http://www.w3.org/TR/2004/WD-semantic-interpretation-20041108/

<rule id="DRINK">
  <one-of>
    <item>coke</item>
    <item>pepsi</item>
    <item>coca cola<tag>coke</tag></item>
  </one-of>
</rule>

This causes a compile error.  I know that by specifying the slotname inside cdata in the tag will make it compile, and I'm not against using cdata, I just don't want to specify the slot, since I will be calling grammars from several different dialogs, with different slot values.  Now, if I just leave the tag out of it entirely, I do get a valid result, but the interpretation matches the utterance.  I want to allow for both 'coke' and 'coca cola' to return 'coke'.  (but not 'new coke' as that would be evil)

Is this possible on the current version you guys are running?

Thanks again,
Shane
MattHenry
4/1/2006 3:35 PM (EST)


Heya Shane,

I'm not aware of any limitations in using the 'return' command within a root rule, but in my testing, it does appear as if there is an existing problem with catching 'anonymous' grammar interpretation values when a slot is not defined.

Until we rectify this bug, you can still specify a slotname in your grammars, and use the <field slot> attribute to make your grammars a bit more universal.

~Matt
safarishane
4/17/2007 8:48 PM (EDT)
Is there a way using <tag> or some other SISR feature to trigger a return of nomatch or noinput by the recognizer?

<one-of>
<item> blue <tag> blue </tag> </item>
<item> yellow <tag> yellow </tag> </item>
<item> auuuuuuuugh <tag> SOMEHOW RETURN NOMATCH </tag> </item>
</one-of>

I want to be able to do this inside the grammar, and not back in the vxml.

Thanks,
Shane
MattHenry
4/18/2007 8:24 PM (EDT)


Heya Shane,

If it was me, I'd probably just do this in the filled section of the return:

<field name="fieldname">

<filled>

<if cond="fieldname == 'auuuuuuuugh'">
  <assign name="fieldname" expr=""/>
  <throw event="nomatch"/>

<elseif cond="fieldname == 'oooooooogh'"/>
<goto next="#NewForm"/>
<else/>
  ...
  </if>
</filled>
</field>


~Matt
safarishane
4/19/2007 12:23 PM (EDT)
Yep, that's the trick though.  I have vxml templates that I use that I don't want to modify.  I just thought it would be nice to be able to specify in the grammar itself that a particular utterance should trigger something other than a match.

Thanks
tonyward
2/12/2008 9:01 AM (EST)
Hi Matt/Jeff,
  I m trying to use tag to return one value for different words a user can utter.  I have copied my grammar snippet below.  Could you please check "UnknownRx" rule?  It should return "empty" for all different words "don't" "forgot" "sorry".  But it returns whatever user spoke.  Please let me know.

Thanks.

        <grammar root ="RxNum" >
        <rule id = "RxNum" scope ="public">
        <one-of>
        <item repeat = "5"><ruleref uri="#digit"/></item>
<item><ruleref uri="#UnknownRx" tag="empty" /></item>
        </one-of>
        </rule>
        <rule id = "digit">
        <one-of>
        <item>1</item>
        <item>2</item>
        <item>3</item>
        <item>4</item>
        <item>5</item>
        <item>6</item>
        <item>7</item>
        <item>8</item>
        <item>9</item>
        <item>0</item>
            </one-of>
        </rule>
<rule id = "UnknownRx">
<one-of>
<item>don't</item>
<item>I don't know</item>
<item>sorry</item>
<item>forgot</item>
</one-of>
</rule>
        </grammar>
voxeojeff
2/12/2008 11:35 AM (EST)
Hey Tony,

A simple grammar modification should do the trick for you.  First, you'll want to remove the 'tag="empty"' attribute.  Next, simply add the following:

<grammar root ="RxNum" >
<rule id = "RxNum" scope ="public">
<one-of>
<item repeat = "5"><ruleref uri="#digit"/></item>
<item><ruleref uri="#UnknownRx"/></item>
</one-of>
</rule>
<rule id = "digit">
<one-of>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>0</item>
</one-of>
</rule>
<rule id = "UnknownRx">
<one-of>
<item>don't[b]<tag> <![CDATA[  <F_1 "empty">  ]]>  </tag>[/b]</item>
<item>I don't know[b]<tag> <![CDATA[  <F_1 "empty">  ]]>  </tag>[/b]</item>
<item>sorry[b]<tag> <![CDATA[  <F_1 "empty">  ]]>  </tag>[/b]</item>
<item>forgot[b]<tag> <![CDATA[  <F_1 "empty">  ]]>  </tag>[/b]</item>
</one-of>
</rule>
</grammar>

Hope this helps,

Jeff
tonyward
2/12/2008 12:52 PM (EST)
Hi Jeff,
  Thanks for the reply.  I tried few other things after emailing you the question.  I changed my grammar to set the tag in the outside rule and that worked.  Here is the snippet:

<item>
  <ruleref uri="#UnknownRx" tag="empty" />
  <tag>$='empty';</tag>
</item>

Setting $='empty' did the trick for me.  Now it returns 'empty' for any word that matches in "UnknownRx".

Thanks for looking it for me,
Vijay
chuchoomar
5/31/2008 12:34 AM (EDT)
the tag element can be used in a dtmf command?.....for instance:


<grammar mode="DTMF" type="application/srgs+xml" root="DTMF" version="1.0" xml:lang="es-es">
    <rule id="DTMF">
      <one-of>
      <item>1
      <tag> <![CDATA[ <room "excel">  ]]> </tag></item>
     
            <item>2
            <tag> <![CDATA[ <room "power point">  ]]> </tag></item>
            <item>3
                    <tag> <![CDATA[  <room "word">  ]]> </tag> </item>

      </one-of>
    </rule>
    </grammar>

i want return the values word , power point and excel but i want to use dtmf command , is it possible?
VoxeoDustin
5/31/2008 10:24 AM (EDT)
Hey,

That will work just fine, however, I recommend using the more recent SISR spec returns instead of the Nuance based returns, unless you have any particular reason you prefer them:

<grammar mode="DTMF" type="application/srgs+xml" root="DTMF" version="1.0" xml:lang="es-es">
    <rule id="DTMF">
      <one-of>
        <item>1
          <tag> out.room="excel" </tag></item>
        <item>2
          <tag> out.room="power point" </tag></item>
        <item>3
          <tag> out.room "word" </tag> </item>

      </one-of>
    </rule>
    </grammar>

This will drop right in to your current code without any other changes, and will save you the trouble of using <![CDATA[ to escape all your returns.

Cheers,
Dustin
mtatum111
9/16/2008 2:41 PM (EDT)
Is this legal?
<grammar type = "application/grammar+xml" root = "color" version = "1.0" xml:lang = "en">
              <rule id = "color" scope = "public">
                  <one-of>
                      <item> red </item>
                        <item> green </item>
                        <item> chartreuse <tag>$ = "green"</tag> </item>
                        <item> blue </item>
                        <item> white </item>
                        <item> black </item>
                  </one-of>
            </rule>
        </grammar>

I was thinking that it should be the following - look at item - chartreuse.

Thanks for any clarification.
<grammar type = "application/grammar+xml" root = "color" version = "1.0" xml:lang = "en">
              <rule id = "color" scope = "public">
                  <one-of>
                      <item> red </item>
                        <item> green </item>
                        <item> chartreuse <tag>green</tag> </item>
                        <item> blue </item>
                        <item> white </item>
                        <item> black </item>
                  </one-of>
            </rule>
        </grammar>
VoxeoDustin
9/16/2008 2:50 PM (EDT)
Hey Melissa,

Both formats are valid. <tag> $ = green </tag> is the older SRGS spec for slot returns. It has been superseded by the 'out.' syntax. The <tag> green </tag> will simply return the value 'green' as the interpretation.

If you wish to use slots, you'll want to use the newer SRGS format:

<tag> out.myslot = "green" </tag>

We can also specify multiple slots:

<tag> out.thisslot = "green"; out.thatslot = "blue" </tag>

We can then retrieve these within VoiceXML with lastresult$.interpretation.thisslot and lastresult$.interpretation.thatslot

Thanks,
Dustin
bany
2/27/2013 1:31 PM (EST)
Hi, I'm sorry for my bad English, anyway what I want to know is a way to solve the following problem:
I have to build a vocal App that can receive many types of requests. An example could be:
APP-How I can help U?
USER--1)I want to know where is the office of Mr. Black.
      2)I want to know if Mr. White is in his office.
      3)Can I leave a message to Mr. Green.
I've already written a grammar file like:

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="it-IT" version="1.0?
mode="voice" tag-format="Nuance">
<rule id="Request" scope="public">
<one-of>
<!-request 1->
<item>
  <ruleref special="GARBAGE"/>
  <item repeat="0-1">
    <ruleref uri="#Where"/>
  </item>
  <item repeat="0-1">
    <ruleref uri="#Verb"/>
  </item>
  <item repeat="0-1">
    <ruleref uri="#Office"/>
  </item>
  <item repeat="0-1">
    <ruleref uri="#Of"/>
  </item>
  <ruleref uri="#MrX"/>
<tag><![CDATA[<Request "Where">]]></tag>
</item>

<!? etc? ?>

</one-of>
</rule>
</grammar>

Obviously "Where","Verb","Office" are subgrammars that I'm omitting now and :

<rule id="MrX" scope="public">
  <one-of>
  <item>Mr. Black<tag><![CDATA[<mr "black">]]></tag>
  </item>
  <item>Mr.White<tag><![CDATA[<mr "white">]]></tag>
  </item>
  <item>Mr. Green<tag><![CDATA[<mr "green">]]></tag>
  </item>
  <!? etc? ?>
  </one-of>
</rule>

Is this the right way to save later the two informations "mr" and "request"?

MattHenry
3/5/2013 2:00 PM (EST)

Hi there,


A few points to be made specific to your request. Firstly, you'll note that the developer postings in this thread specify an older semantic interpretation format for <tag> which should be avoided, as this is not per the W3C specification for SISR:

* http://www.w3.org/TR/semantic-interpretation/

In a general sense, any code that you see contained within a tag thats in this format....

<tag><![CDATA[  <MySlot "variable value">  ]]></tag>


... should be changed to be W3C-compliant:

<tag>out.MySlot= "variable value";</tag>

In your case, note that abbreviated utterances wont recognize well, so I think you'd want to have your semantic regognition specified as follows:

<item>Mister Green<tag>out.mr="green";></tag>


Secondly, it's important to mention that attempting to recognize any arbitrary speech via the hosted recognition engines are going to have inconsistent accuracy at best due to problems inherent with such using a non-adaptive engine: Disambiguation issues resulting in mis-matching, and out-of-grammar recognition results are to be expected, I'm afraid, and this is essentially a limitation of todays ASR technology, unless you'd want to consider a (somewhat expensive) custom deployment of an adaptive (aka "learning") speech recognition engine.


I hope that this explanation, and these words of caution are of some assistance to you.


Regards,


Matthew Henry


login



© 2013 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site