You Have Options... Option Lists, that is
Now that you have created and used in your own code a simple “Hello World” recognizer.json file you are ready to enhance it. As in the previous tutorials, ensure that you have node and npm installed, create a new directory and initialize npm project there (accepting default values):
Note: if you don’t want to type in all the source code, you don’t have to. This tutorial is available as an npm module. Simply load the module, then copy all the files to your current directory:
When you created the Hello World recognizer.json file, it only contained a single utterance that it could understand. Wouldn’t it be nice if all sorts of greetings could be understood and mapped to the GreetingIntent? That’s easy to do, you can simply add more lines, like these to the utterances.txt file:
and so on. While this would work, it’s hardly elegant. It requires you to keep adding every possible permutation of simple greetings. Luckily for you, vui-ad-hoc-alexa-recognizer gives you an ability to specify many variations at once. This feature is called option lists. In the usual spirit of simplicity, it’s rather easy and intuitive to use. Let’s say that you wanted to replace the above 4 utterance with just one that uses option lists. We’ll do it in two steps. First, we’ll create a simple utterance that comibines these two into one:
now becomes:
What the funny curly bracket expression means is “any of the individual strings separated by | will match”.
Now, let’s replace all 4 of the utterances with just a single one using 2 separate option lists:
The second set of curly brackets looks a little funny - it still has a “|” in it but there is only one string inside - “, how are you”. This is intentional. What that means is that this string is optional - if it’s not in the text being matched, the match will not fail because this string isn’t there. Go ahead and try it. Assuming you’ve downloaded the tui-youhaveoptions tutorial source (or kept you index.js from the privious tutorials), let’s test it:
So, how many variations will a single utterance with option lists match? It’s easy to compute - simply multiply the number of options within each list (counting the empty options) by the number of options in each other option list. So, here we have 2 * 2 = 4, exactly as designed. How about this utterance (found in the tutorial source):
The answer is 8 * 2 * 3 = 48. Now, that’s an efficient way to generate utterances. Here is a list of utterances that you would have had to enter by hand to create equivalent matches:
Btw, vui-ad-hoc-alexa-recognizer DOES NOT generate these unfolded lists internally - it’s more intelligent than that and simply matches on a single utterance with “variations”. This is important for performance reasons - matching on a single utterance with variations is faster than matching on many separate utterances.
Of course, if you have completely unrelated utterances, there is no need to try to get them into a single one using option lists. You can still list multiple ones on separate lines: