Search code examples
grammarpocketsphinx

Does a JSGF file only use one public rule?


I use the following JSGF file with pocketsphinx (in french sorry):

#JSGF V1.0;
/**
* JSGF Grammar for music
*/
grammar music;

<launch_app>    = lance | ouvre;
<launch_radio>  = commence | débute | démarre;                                                      
<launch_artist> = met (du) | joue;

<app_list>      = spotify | youtube | soundcloud | deezer;
<radio_list>    = rock | folk | pop | classique | métal | triste | joyeuse | détendu;
<artist_list>   = moby | lori | kyo | shakira | pantera | mozart;

<name>  = music;

<radio_command> = <name> <launch_radio> une radio <radio_list>;
<app_command>   = <name> <launch_app> <app_list>;
<artist_command> = <name> <launch_artist> <artist_list>;

public <final_rule> = <radio_command> | <app_command> | <artist_command>;

And it perfectly works. But if I remove the <final_rule> tag and use multiple public keywords instead, like this:

#JSGF V1.0;
/**
* JSGF Grammar for music
*/
grammar music;

<launch_app>    = lance | ouvre;
<launch_radio>  = commence | débute | démarre;                                                      
<launch_artist> = met (du) | joue;

<app_list>      = spotify | youtube | soundcloud | deezer;
<radio_list>    = rock | folk | pop | classique | métal | triste | joyeuse | détendu;
<artist_list>   = moby | lori | kyo | shakira | pantera | mozart;

<name>  = music;

public <radio_command> = <name> <launch_radio> une radio <radio_list>;
public <app_command>   = <name> <launch_app> <app_list>;
public <artist_command> = <name> <launch_artist> <artist_list>;

pocketsphinx only recognize one of the three public rules, regardless what I say. I find this behavior strange because pocketsphinx don't give me errors while running with this grammar file. Does a JSGF file only need one public keyword or is it link to pocketshphinx ?


Solution

  • Yes, pocketsphinx recognizes just the first rule by default. If you want to use other rules, there is -toprule parameter in config or name parameter in API.

    If you want to recognize multiple choices, you can construct grammar in the way that there is a final rule constructed as a choice of all the rules you need:

     public <command> = <artist> | <music> | <action> ;