Does a JSGF file only use one public rule? - grammar

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 ?

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> ;

Related

how to handle passing of product category to the Products Controller in Laravel

I used command below to create a ProductsController (Note: I'm new to Laravel and PHP)
php artisan make:controller ProductsController --model=Product
I see that it created a controller with an index() function like below:
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
//
}
What would be the best way to give it the ability to show products by category? My thought is to make a route like this:
/products/{category}. So, I created a Category Enum and added that as the parameter of the index function (see below). But it does not work. Because when I entered an url like this http://localhost:8000/admin/products/Parts, it does not hit the /products/{category} route. Instead, it is hitting the "products/{product} ......... products.show" route.
// create a Category ENUM
namespace App\Enums;
enum Category: string
{
case Parts = 'Parts';
case Vehicles = 'Vehicles';
case All = 'All';
}
// Change the index method in the ProductsController to be like below
public function index(Category $category)
{
return $category->value;
}
// below is how I define the routes
Route::resource('products', ProductsController::class);
Since a product belongs to a particular category, you should instead define your route as:
Route::resource('categories.products', ProductsController::class);
That would generate the routes below:
$ php artisan route:list | grep "categories.products"
| | GET|HEAD | categories/{category}/products | categories.products.index | App\Http\Controllers\ProductsController#index | web |
| | POST | categories/{category}/products | categories.products.store | App\Http\Controllers\ProductsController#store | web |
| | GET|HEAD | categories/{category}/products/create | categories.products.create | App\Http\Controllers\ProductsController#create | web |
| | GET|HEAD | categories/{category}/products/{product} | categories.products.show | App\Http\Controllers\ProductsController#show | web |
| | PUT|PATCH | categories/{category}/products/{product} | categories.products.update | App\Http\Controllers\ProductsController#update | web |
| | DELETE | categories/{category}/products/{product} | categories.products.destroy | App\Http\Controllers\ProductsController#destroy | web |
| | GET|HEAD | categories/{category}/products/{product}/edit | categories.products.edit | App\Http\Controllers\ProductsController#edit | web |
In your frontend source code, you could use this URL path:
http://localhost:8000/admin/categories/Parts/products

Passing Data from a Data Table in the feature file to my step definitions (js)

I'm trying to pass Data from a table into a feature file and then finally onto my java script step-definitions, shown below.
Scenario: XX | Basket Tests: Cover Type | Building + no bundle + HE
Given I open the page with the url "http://localhost:3000" and route "/basket"
When I click the button <coverTypeID>
And I click the button <bundleID>
Then I see the result <expectedResult>
| id | url | coverTypeID | bundleID | elementID | expectedResult |
| 1 | http://localhost:3000/basket | coverTypeId101 | NoBundle | null | |
| 2 | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox1 | |
| 3 | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox2 | |
| 4 | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox3 | |
| 5 | http://localhost:3000/basket | coverTypeId101 | NoBundle | checkbox4 | |
Is my Feature file, i used to pass data using strings however now i am using the data table it doesn't identify the scenario when the tests run.
When("I click the button <coverTypeID>", (buttonID, next) => {
driver.findElement(By.id(buttonID)).then(pageElement => { /////////////////////////////////////////////
driver.wait(until.elementIsVisible(pageElement), 10000).then(async () => { //This is to click a button using elementID//
await driver.sleep(3000); /////////////////////////////////////////////
pageElement.click();
next();
})
.catch(ex => {
console.log(ex.message, ex.stack)
});
}).catch(ex => {console.log(ex.message, ex.stack)});
});
The error i'm getting is that the tests are undefined as the scenario doesn't match the step definition properly because of the usage of the table titles
I've looked at using Regular Expressions however i'm not sure what type of data the data table passes when executing, any guidance would be of use, i've went through a bunch of different questions and none quite seem to answer mine.
Any help would be greatly appreciated, i'd like to avoid regular expression if i could because the aim is to make the code as readable as possible.
Thank you in advance.
so i found the solution, rather than expecting the title of the data table i referred back to using {string}
When("I click the button {string}", (buttonID, next) => {
Then in the data table i realised the mistake i was making was simply not adding quotation marks to make the data into string format.
Examples:
| id | coverTypeID | bundleID | elementID |
| 1 | "coverTypeId101" | "moreDetails1" | "checkbox2" |
By doing this the feature now sucessfully pulls data from the feature file into the JS file.

Nested examples in cucumber scenario outline - List or Map values

I have recently seen a cucumber scenario outline like this.
sorry for my bad example below. But the format is in this way.
I really wonder if this type of format is supported by cucumber?
The nested Data tables. Has any one used this type of nested Data table?
If yes is this the below format?
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |teapot|
| <item2> |Yorkshire tea|
Examples:
| user | searchTerm |
| Adam | Tea |
Can i make a data table like above
That's not quite how they work.
The nested data tables are used by the step that the table is joined to. It's usually used to do multiple of the same thing, using the data table on the inside as an array. This can include headers, or no headers - depending on how you have written your step. Remember - it's all about communication.
As an example:
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |
| <item2> |
Examples:
| user | searchTerm | item1 | item2 |
| Adam | Tea | teapot | Yorkshire tea |
Updated Answer!!
As #kayle mentioned in his answer.. You can write following test scenario's
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| Teapot |
| Yorkshire tea |
Examples:
| user | searchTerm |
| Adam | Tea |
or
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |
| <item2> |
Examples:
| user | searchTerm | item1 | item2 |
| Adam | Tea | Teapot| Yorkshire tea|
the second scenario will be useful if you want to add different items for each user. for example:
Scenario Outline: Hello World
Given I am logged in as <user>
When I search for <searchTerm>
Then I add the following to my basket:
| <item1> |
| <item2> |
Examples:
| user | searchTerm | item1 | item2 |
| Adam | Tea | Yorkshire tea | Teapot |
| Tom | Books | book1 | book2 |
Hope it's clear!!

JSFG grammar not parsing

I can't see where im breaking my jsfg grammar (for Sphinx4).
Or is there any debugging tool for parsing?
This compiles:
#JSGF V1.0;
grammar dialog;
<digit> = oh |
zero |
one |
two |
three |
four |
five |
six |
seven |
eight |
nine ;
<number> = <digit>+ [point <digit>+];
<menu_command> = digits |
[go to [the]] bank account |
weather forecast |
[play] music |
v |
hud |
exit [[the] program] ;
<bank_command> = [show | check] balance |
deposit <number> |
withdraw <number> |
back ;
<artist_command> = elvis |
moby |
[the] beatles |
sia |
random;
<song_command> = [a little less] converstion |
moby |
[the] beatles |
sia ;
<music_command> = [play] music;
public <command> = <menu_command> | <bank_command>;
But this doesnt:
#JSGF V1.0;
grammar dialog;
<digit> = oh |
zero |
one |
two |
three |
four |
five |
six |
seven |
eight |
nine ;
<number> = <digit>+ [point <digit>+];
<hud_command> = voicehud | hud
<menu_command> = digits |
[go to [the]] bank account |
weather forecast |
v |
hud |
exit [[the] program] |
hide ;
<bank_command> = [show | check] balance |
deposit <number> |
withdraw <number> |
back ;
<artist_command> = elvis |
moby |
[the] beatles |
sia |
random;
<song_command> = burning love |
moby |
[the] beatles |
sia ;
<album_command> = [one thousand] forms of fear |
play |
[the] white album |
burning love ;
<musicapp_command> = play | music;
<music_selector_command> = artist | song | album | random | mix;
<music_selection_command> = <artist_command> | <song_command> | <album_command>;
<music_command> = <musicapp_command><music_selector_command><music_selection_command>;
public <command> = <menu_command> | <bank_command> | <music_command>;

What are all the standard CGI environment variables?

CGI scripts should have access to a list of environment variables set by the web server. What are their names?
See RFC 3875 for the CGI spec, which has all the info you need. :-)
From the RFC:
meta-variable-name = "AUTH_TYPE" | "CONTENT_LENGTH" |
"CONTENT_TYPE" | "GATEWAY_INTERFACE" |
"PATH_INFO" | "PATH_TRANSLATED" |
"QUERY_STRING" | "REMOTE_ADDR" |
"REMOTE_HOST" | "REMOTE_IDENT" |
"REMOTE_USER" | "REQUEST_METHOD" |
"SCRIPT_NAME" | "SERVER_NAME" |
"SERVER_PORT" | "SERVER_PROTOCOL" |
"SERVER_SOFTWARE" | scheme |
protocol-var-name | extension-var-name
protocol-var-name = ( protocol | scheme ) "_" var-name
scheme = alpha *( alpha | digit | "+" | "-" | "." )
var-name = token
extension-var-name = token
http://www.cgi101.com/book/ch3/text.html
The "hoohoo" machine at NCSA that has the CGI documentation is down, but here's what seems to be a mirror.
A quick Google search finds the what you need.