How to write grammar rules in a <data> element in an scxml file?

150 Views Asked by At

I have some trouble figuring out how to write grammar rules inline directly in scxml files instead of linking to them in an external grxml files.

Let me illustrate it on an example:

combat.scxml
------------
<?xml version="1.0" encoding="utf-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" xmlns:vxml="http://www.w3.org/2001/vxml" version="1.0" initial="Start">
    <state id="WeaponChoice">
        <onentry>
            <vxml:prompt>What kind of weapon do you want to use?</vxml:prompt>
        </onentry>
        <datamodel>
            <data id="WeaponChoiceGrammar" expr="./combat.grxml#weapon"/>
        </datamodel>
    </state>
</scxml>

combat.grxml
------------
<?xml version="1.0" encoding="utf-8"?>
<grammar>
    <rule id="weapon">
        <one-of>
            <item>sword</item>
            <item>knife</item>
            <item>hammer</item>
            <item>bow</item>
            <item>crossbow</item>
        </one-of>
    </rule>
</grammar>

If I wanted to write that grammar rule inline in the <data> element in combat.scxml, I would do it like this:

combat.scxml
------------
<?xml version="1.0" encoding="utf-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" xmlns:vxml="http://www.w3.org/2001/vxml" version="1.0" initial="Start">
    <state id="WeaponChoice">
        <onentry>
            <vxml:prompt>What kind of weapon do you want to use?</vxml:prompt>
        </onentry>
        <datamodel>
            <data id="WeaponChoiceGrammar">
                <rule id="weapon">
                    <one-of>
                        <item>sword</item>
                        <item>knife</item>
                        <item>hammer</item>
                        <item>bow</item>
                        <item>crossbow</item>
                    </one-of>
                </rule>
            </data>
        </datamodel>
    </state>
</scxml>

Now, let's suppose combat.grxml is like this:

combat.grxml
------------
<?xml version="1.0" encoding="utf-8"?>
<grammar>
    <rule id="weapon">
        <one-of>
            <item tag="melee"><ruleref uri="#melee"/></item>
            <item tag="ranged"><ruleref uri="#ranged"/></item>
        </one-of>
    </rule>
    <rule id="melee">
        <one-of>
            <item>sword</item>
            <item>knife</item>
            <item>hammer</item>
        </one-of>
    </rule>
    <rule id="ranged">
        <one-of>
            <item>bow</item>
            <item>crossbow</item>
        </one-of>
    </rule>
</grammar>

Now, how could I write that inline in the <data> element in combat.scxml, like I did in the previous case?

1

There are 1 best solutions below

0
On

This is pretty much undefined as per SCXML recommendation and will depend on your platform. I doubt, however, that merely mixing vxml and scxml namespaces is sufficient with any compliant SCXML interpreter. You would, most likely, need to invoke a VoiceXML browser and send VoiceXML markup as part of send requests or provide custom elements for executable content in the vxml namespace.

There is some preliminary support for the JVoiceXML VoiceXML interpreter as an invoker in uSCXML (via W3C MMI life-cycle events) and you can register your own elements as executable content in custom namespaces, allowing for both approaches.