Utterance expansion notation allows you to more efficiently build out the sample utterances of your intent. You can quickly account for variations in carrier phrases, contractions, and other optional words like "please" or "ok".
To elaborate, Alexa recommends you think about all the possible variations of a sample utterance and add them to your intent. In their example for a horoscope skill, they suggest you add a sample of "what's" to account for "what is". This means you need to go from one sample utterance:
what is the horoscope
to two:
what is the horoscope
what's the horoscope
The only difference in these two utterances is the first part, while the rest is the same. You can leverage this pattern by using expansion notation:
{what is|what's} the horoscope
The items that will be expanded are within the curly brackets { } and are delimited by a pipe |. Sometimes it is helpful to think of it as an array of items that will be replaced.
When this is expanded programmatically, you end up with the same result:
what is the horoscope
what's the horoscope
Notice how it then plays out when you want to add "please" at the end.
Instead of duplicating an utterance and then adding "please" to the end of each, you can add:
{please|}
which expands to "please" and an empty line:
please
You can even include slots within the expansion. Let's say you want to include an optional acknowledgement word like "ok" or "gotcha" at the beginning of your sample.
{${acknowledgement}|} show me the ${ordinal} one
This is then expanded to:
${acknowledgement} show me the ${ordinal} one
show me the ${ordinal} one
Best Practices
- Balance simplification with clarity. Using too much expansion notation will make it harder to understand by others.
- Do not nest expansion notation, it is not supported
Comments
0 comments
Article is closed for comments.