Patterns

When writing commands, you need to provide phrases that the user can say to invoke these commands. In Alan AI, these phrases are known as patterns.

For example, in the intent below, How do I begin? is a pattern:

Dialog script
intent('How do I begin?', p => {
    p.play('Ask me a question or give a task');
});

Alternatives in patterns

Patterns may contain alternatives. Alternatives comprise a list of possible words and phrases that the user can say to invoke the command. To provide alternatives in the pattern, use the | delimiter and enclose the alternative set in brackets ().

For example, to invoke the command below, the user can ask: How do I start? or How do I begin?:

Dialog script
intent('How do I (begin|start)?', p => {
    p.play('Ask me a question or give a task');
});

Alan AI supports nested syntax for alternatives. In the example below, the command can be invoked with the following phrases:

  • How do I begin here?

  • How do I start here?

  • How can I begin here?

and so on:

Dialog script
intent('How ((do|can) I (begin|start)) here?', p => {
   p.play('Ask me a question or give a task');
});

Optional words and phrases

In commands and responses, some parts of patterns may be optional.

  • To make a single word optional, add the - character at the end of it

  • To make a phrase or alternative set optional, enclose it in brackets and add the - character at the end of it

This will notify Alan AI that the command can be invoked both with and without the words provided in the optional part.

Dialog script
intent('How ((do|can) I (begin|start)) here-?', p => {
    p.play('Ask me a question or give a task');
});

intent('What (questions|type of questions)- can I ask here-?', p => {
    p.play('You can ask me any question about the cloud environment');
});

Alan AI supports nested syntax for optional words and phrases. In the example below, the command can be invoked with the following phrases:

  • What can I ask?

  • What can I ask here?

  • What questions can I ask here?

  • What kind of questions can I ask here?

and so on:

Dialog script
intent('What ((kind of|type of)- questions)- can I ask here-?', p => {
    p.play('You can ask me any question about the cloud environment');
});

Alternatives and optional phrases make the AI assistant’s responses more diverse and help Alan AI successfully invoke commands added to the dialog script. When writing commands, include all possible variants of the phrases the user can say. The more closely the user’s phrase matches the intent pattern, the higher the match score. For details, see Intent matching.

Multiple patterns

You can add multiple patterns to commands. Multiple patterns can be helpful if you want to let users invoke the same command with completely different phrases.

To define multiple patterns, pass them to the intent() function as comma separated strings:

Dialog script
intent('How do I start here?', 'What is the first step?', p => {
    p.play('Ask me a question or give a task');
});

Multiple patterns can also be passed to the intent() function as an array:

Dialog script
let requests = [
    'How do I start here?',
    'What is the first step?'
];

intent(requests, p => {
    p.play('Ask me a question or give a task');
});