"Is there a way to loop rules in a .grxml file?"

269 Views Asked by At

I'm trying to build a GVP application via Composer (Genesys Framework) that needs to accept an input through speech recognition. The input consist of an alphanumeric code of 12 or more letters/numbers where the speaker needs to use name of italian cities in place of letters.

I already tried to write a code for my grammar using the grammar builder in Genesys Composer but this way it only accept ONE word. So i started to write a .grxml code from scratch (I have basically no knowledge about this kind of language). I came up with the following:

<?xml version="1.0"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="it-IT" version="1.0"
         root="codice">

    <rule id="A" scope="public">
      <item repeat="0-5">
        <one-of>
            <item>Ancona</item>
            <item>A</item>
        </one-of>
      </item>
    </rule>

    <rule id="B" scope="public">
      <item repeat="0-5">
        <one-of>
            <item>Bologna</item>
            <item>Bari</item>
            <item>Bi</item>
            <item>B</item>
        </one-of>
      </item>
    </rule>

    <rule id="C" scope="public">
      <item repeat="0-5">
        <one-of>
            <item>Como</item>
            <item>Ci</item>
            <item>C</item>
        </one-of>
      </item>
    </rule> 

    <rule id="D" scope="public">
      <item repeat="0-5">
        <one-of>
            <item>Domodossola</item>
            <item>Di</item>
            <item>D</item>
        </one-of>
      </item>
    </rule>
        
    <!-- Reference by URI to a local rule -->
    <rule id="codice" scope="public">
        <item repeat="0-5"> 
            <ruleref uri="#A" />
            <ruleref uri="#B" />
            <ruleref uri="#C" />
            <ruleref uri="#D" />
        </item>     
    </rule> 

</grammar>

The grammar works but only if I pronounce the words in order. For example if I pronounce "ANCONA, COMO" I got the right result and if I print my input variable it contains "ANCONA COMO". Instead, if I pronounce "COMO, ANCONA" my variable only contains the word "COMO". How can I "loop" through my rules in order to get words pronounced in random order? Thank you.

2

There are 2 best solutions below

0
On

I think you should try something like this, but your case is complex. You can found specification here

<?xml version="1.0"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="it-IT" version="1.0"
         root="codice">

    <rule id="A" scope="public">
      <item>
        <tag>out+="A"</tag>
        <one-of>
            <item>Ancona</item>
            <item>A</item>
        </one-of>
      </item>
    </rule>

    <rule id="B" scope="public">
      <item>
        <tag>out+="B"</tag>
        <one-of>
            <item>Bologna</item>
            <item>Bari</item>
            <item>Bi</item>
            <item>B</item>
        </one-of>
      </item>
    </rule>

    <rule id="C" scope="public">
      <item>
        <tag>out+="C"</tag>
        <one-of>
            <item>Como</item>
            <item>Ci</item>
            <item>C</item>
        </one-of>
      </item>
    </rule> 

    <rule id="D" scope="public">
      <item>
        <tag>out+="D"</tag>
        <one-of>
            <item>Domodossola</item>
            <item>Di</item>
            <item>D</item>
        </one-of>
      </item>
    </rule>
        
    <rule id="code" scope="public">
        <one-of>
          <item> <ruleref uri="#A" /></item>
          <item> <ruleref uri="#B" /></item>
          <item> <ruleref uri="#C" /></item>
          <item> <ruleref uri="#D" /></item>  
        </one-of>     
    </rule>     
        
    <!-- Reference by URI to a local rule -->
    <rule id="codice" scope="public">
        <item repeat="12-"> 
            <ruleref uri="#code" />
        </item>     
    </rule> 

</grammar>
0
On

Perhaps I am misunderstanding but isn't this what you need?

<rule id="A" scope="public">
    <item repeat="12">
    <one-of>
        <item>Ancona</item>
        <item>A</item>
        <item>Bologna</item>
        <item>Bari</item>
        <item>Bi</item>
        <item>B</item>
        <item>Como</item>
        <item>Ci</item>
        <item>C</item>
    </one-of>
    </item>
</rule>

Having said that I can't imagine this working very well with such long inputs. You might need to confirm each input...