VoiceXML 2.1 Development GuideHome  |  Frameset Home

  grXML Subgrammars  |  TOC  |  Nuance Extension Grammars  

Inline XML Subgrammars

XML subgrammar structures can also be included inline, although it does seem to create additional clutter within your code. It is advisable to first define your grammar as a separate file,  and then include it within the VoiceXML code when you are satisfied that it is working properly, thus keeping your code as modular as possible. Do keep in mind the filesize limitation of 100k per document when designing your application; a good rule of thumb is to keep larger subgrammar structures as external documents rather than including them inline. This being said, a grXML subgrammar can be ported from an external document to an inline structure with absolutely no change to the grammar structure, and but one or two minor changes to the VoiceXML code:



<?xml version="1.0"?>
<vxml version = "2.0" xmlns="http://www.w3.org/2001/vxml">

  <form>
    <field name="F_1">
      <prompt>
        What is my name, biz nitch?
      </prompt>

  <grammar xml:lang="en-US" root = "TOPLEVEL">

    <rule id="TOPLEVEL" scope="public">
      <item>

      <!-- FIRST NAME RETURN -->
          <item repeat="0-1">
              <ruleref uri="#FIRSTNAME"/>
  <tag>assign(a $return)</tag>
          </item>

        <!-- MIDDLE NAME RETURN -->
            <item repeat="0-1">
              <ruleref uri="#MIDDLENAME"/>
    <tag>assign(b $return)</tag>
            </item>


      <!-- LAST NAME RETURN -->
            <ruleref uri="#LASTNAME"/>
                        <tag>assign(c $return)</tag>
    </item>

      <!-- TOP LEVEL RETURN --> 
                <tag><![CDATA[ <F_1 (strcat($a strcat($b $c)))> ]]> </tag>

        </rule>

  <rule id="FIRSTNAME" scope="public">
          <one-of>
                <item> matthew 
                    <tag> return ("matthew ")  </tag>
                </item>
                <item> dee         
                  <tag> return ("dee ")  </tag>
                </item>
                <item> jon           
                  <tag> return ("jon ")  </tag>
                </item>
                <item> george   
                  <tag> return ("george ")  </tag>
                </item>
                <item> billy         
                  <tag> return ("billy ")  </tag>
                </item>       
            </one-of>
    </rule>

  <rule id="MIDDLENAME" scope="public">
          <one-of>
                <item> warren     
                  <tag> return ("warren ")  </tag>
                </item>
                <item> dee           
                  <tag> return ("dee ")  </tag>
                </item>
                <item> bon           
                  <tag>return ("bon ")  </tag>
                </item>
                <item> double ya 
                  <tag> return ("w ")  </tag>
                </item>
                <item> dee         
                  <tag> return ("dee ")  </tag>
                </item>         
            </one-of>
    </rule>

  <rule id="LASTNAME" scope="public">
          <one-of>
                <item> henry   
                  <tag> return ("henry ")  </tag>
                </item>
                <item> ramone 
                  <tag> return ("dee ")  </tag>
                </item>
                <item> jovi 
                  <tag> return ("jovi ")  </tag>
                </item>
                <item> bush     
                  <tag> return ("bush ")  </tag>
                </item>
                <item> williams 
                  <tag> return ("williams ")  </tag>
                </item>     
            </one-of>
    </rule>
  </grammar>
    <filled>
      <prompt>
        You said that yo daddy is <value expr="F_1"/>.
      </prompt>
    </filled>
    </field>
  </form>
</vxml>




  ANNOTATIONS: EXISTING POSTS
mf.mctear
5/31/2007 6:55 AM (EDT)
I have been trying to use <tag> to return a different value from the one recognised. This works for a simple grammar e.g.
<rule id="FIRSTNAME" scope="public">
<item> alexander
<tag> return ("henry ") </tag>
</item>
</rule>
- returns "henry"

but does not work if this rule is called as a sub-grammar. I have tried different permutations of your example of an inline sub-grammar. This is a simple version:

<?xml version="1.0"?>
<vxml version = "2.0" xmlns="http://www.w3.org/2001/vxml">

<form>
<field name="F_1" >
<prompt>
What is my name?
</prompt>

<grammar xml:lang="en-US" root = "TOPLEVEL">

<rule id="TOPLEVEL" scope="public">
<item>
<ruleref uri="#FIRSTNAME"/>
</item>
</rule>

<rule id="FIRSTNAME" scope="public">
<item> alexander
<tag> return ("henry ") </tag>
</item>
</rule>
</grammar>
<filled>
<prompt>
You said that my name is <value expr="F_1"/>.
</prompt>
</filled>
</field>
</form>
</vxml>

- returns 'alexander'

How can I pass the value 'henry' up to TOPLEVEL?
VoxeoDante
5/31/2007 1:35 PM (EDT)
Hello,

In order to access the interpretation value in a subgrammar you have to assign the value to a slot. When you assign a slot, it allows the interpretation value to be passed back up to the toplevel rule. Without the slot assignment the subgrammar will only return the utterance value and not the interpretation value. The code should be formatted in this way.

<?xml version="1.0"?>
<vxml version = "2.0" xmlns="http://www.w3.org/2001/vxml">

<form>
<field name="F_1" >
<prompt>
What is my name?
</prompt>

<grammar xml:lang="en-US" root = "TOPLEVEL">

<rule id="TOPLEVEL" scope="public">
<item>
<ruleref uri="#FIRSTNAME"/>
</item>
</rule>

<rule id="FIRSTNAME" scope="public">
<one-of>
<item> alexander
<!--  Assigns the value to a slot -->
<tag><![CDATA[ <F_1 "henry"> ]]> </tag>

</item>
</one-of>
</rule>
</grammar>
<filled>
<prompt>
You said that my name is <value expr="F_1"/>.
</prompt>
</filled>
</field>
</form>
</vxml>

If you have any further questions please let me know.

All the Best,
Dante Vitulano
mf.mctear
6/2/2007 12:14 PM (EDT)
Thanks - that works fine.
Now I have another problem - I want to assign values from the same subgrammar to different slots. Based on the Nuance specification I have the followiung grammar which relates to a mixed-initiative form:

banking_test.grxml

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

<rule id="transfer" scope="public">
<item> from <ruleref uri="#account"/>
<tag> assign (s $return) </tag>
</item>
<item> to <ruleref uri="#account"/>
<tag> assign (d $return) </tag>
</item>
<tag> <![CDATA[<source $s> <destination $d>]]> </tag>
</rule>

<rule id = "account" scope = "public">
  <one-of>
  <item> savings  </item>
  <item> current  </item>
  </one-of>
</rule>

</grammar>

transfer_mixed.vxml

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

<form scope="dialog">
<grammar src="banking_test.grxml#transfer" mode="voice"/>

<initial name="start">
<prompt>
say savings current
</prompt>
</initial>

<field name="source" modal="false">
  <prompt>
  what is the source account?
  </prompt>
<grammar src="banking_test.grxml#account" mode="voice"/>
</field>

<field name="destination" modal="false">
  <prompt>
  what is the destination account?
  </prompt>

  <grammar src="banking.grxml#account" mode="voice"/>

  </field>

<filled>
you said from <value expr="source"/> to  <value expr="destination"/>
</filled>

  </form>
</vxml>

but I can't get it to fill the slots.
Your help would be much appreciated.
VoxeoDante
6/4/2007 12:53 PM (EDT)
Hello,

I will be working on an answer for you, but I want to make sure you understand mixed initiative subgrammars are time consuming. This matter will take some time to resolve. I will update this ticket as soon as I have an answer for you.

All the Best,
Dante Vitulano
MattHenry
6/4/2007 4:59 PM (EDT)


Hi there,

I think that the problem here stems from a misunderstanding of how the top-level rules work in conjunction with a mixed-initiative document structure. In checking the tutorial on mixed init, take note of the following:


1) The form-scoped grammar references the rule that has *both* slots defined, (ie what you currently have in your grammar).


2) There are more than one top-level rule possibility defined in the grammar:

a) Utterance #1, *and* Utterance #2
b) Utterance #1 only
c) Utterance #2 only


3) Each field references a sub-rule that defines the utterance/interp value specifically for the field.

Keeping these facts firmly in mind, it's clear that the grammar needs some additional rules defined, and that the grammar references in the VXML need to be changed to reflect this.


Hope that this helps to steer you in the right direction,

~Matthew Henry


mf.mctear
6/5/2007 2:38 PM (EDT)
Thanks for the help so far. Looking at this rule:
<rule id="transfer" scope="public">
<item> from <ruleref uri="#account"/>
<tag> assign (s $return) </tag>
</item>
<item> to <ruleref uri="#account"/>
<tag> assign (d $return) </tag>
</item>
<tag> <![CDATA[<source $s> <destination $d>]]> </tag>
</rule>
I had thought that e.g. with input 'savings current' when the sub-grammar 'account' was called, it would assign 'savings' to 's' via $return then 'current' to 'd', then s and d would be assigned to 'source' and 'destination' respectively. This is how I understood the example in the Nuance documentation on XML grammars. Is there still something missing?
I can get it to work by having separate subgrammars for source account and destination account, but I wanted generality by having the account types listed only once and then assigning their values through the top level rule.
MattHenry
6/6/2007 4:11 PM (EDT)

Hi again,

As both "savings" and "current" are seperate <items> defined in the same rule, then I don't see how this would even be a valid utterance: chances are, that we would get a "nomatch" event, (or at best, "savings" would be recognized, while "current" would be ignored. Also, be aware that we need to define explicit slot names to the grammar returns, and that the "assign (d $return)" stuff doesn't really come into play unless we are concatenating seperate utterances from subgrammars into a single string value.

In an effort to help illustrate what your grammar structure should be modeled after I have attached some VXML and grammars that should help steer you towards a path of Mixed-Initiative Righteousness. If, after reviewing this code, you have any remaining questions, please do let me know what I can do to help out.

Regards,

~Matthew henry

login
  grXML Subgrammars  |  TOC  |  Nuance Extension Grammars  

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