Template syntax
Sometimes you want your bot to react to specific phrase templates instead of all possible phrases that are more or less similar in their meaning.
For this, enter a template of your phrase when adding a new intent.
By default, when you go to the Intents block and add new intents, they are added as sample phrases, not as templates. It is indicated by the icon next to each phrase. To turn the sample phrase into a template, click the icon next to each phrase you want to make a template. It will change to the icon.
What are phrase templates?
A template is a sequence of words and entities that have to be there in a phrase for the bot to react to it. Templates, like intents, are recognized by the classifier threshold.
Basically, they are similar to regular expressions but with simplified syntax.
Template syntax
To create a new template, use a special syntax.
Using this syntax, you can write flexible templates which will help the bot understand the client’s phrases.
Look at the examples below:
hi
This template that contains only one word will make the bot react only at the exact word hi
. If the phrase differs by at least one character, the bot will not recognize it.
* look* *
In this case, the word “look” can have various endings. Also, the client’s phrase can contain any number of words before and after this word.
This template will make the bot recognize the phrases like “look”, “I am looking for a new iPhone”, “I have looked through your site”, etc.
* ~agree *
The template makes the bot recognize all forms of the “agree” verb, as well as two to three words before and after it.
For example, the template will work for the phrase “Have you agreed?”.
You can see the whole Tovie DialogStudio template syntax below.
Word
In the template, the word is not expanded with synonyms. To be recognized by the bot, the word should be written by the client exactly as it is specified in the template.
Asterisk
The asterisk (*) means the client’s phrase can include any number of characters, including none.
* cat
The phrase can include any number of words before the word cat
. The template will work for the phrases “cat”, “small cat”, etc.
* cat * small *
The template allows you to write two to three words before, between, and after the words “cat” and “small”.
For example, it will work for the phrase “the black cat is very small”, but will not work for “cats are small”.
The cat*
template will work for “cat”, “cats”, “cat’s”, etc. If you do not specify that there can be other words before and after the word cat
, the bot will not recognize phrases with this word.
The *fall*
template will work for “fall”, “waterfall”, “waterfalls”, “falls”, etc.
Tilde
Use tilde (~) to make the bot recognize all forms of the word, but of the same part of speech. The tilde should be specified before the initial form of the word.
For example, the ~agree
template will work for all forms of the “agree” verb — “agree”, “agrees”, “agreed”, “agreeing”, etc. But there are some restrictions for such templates:
- It will not work for other parts of speech, e.g., “agreement”.
- It will not work for words containing suffixes or prefixes, e.g., “disagree”.
Alternative
Enclose several words or other templates in brackets so that the template will work for any of these words in the client’s phrase.
For example, (cat/catty/kitten)
or (cat|catty|kitten)
will work for any of the words “cat”, “catty”, or “kitten”.
The * (~cat / ~kitten) *
template will work for any form of the word “cat” and any form of the word “kitten”. At the same time, the phrase can contain any number of words before and after the word “cat” or “kitten”. It will work for “I love black kittens” or “All cats are cute”.
Permutations
Enclose the template in braces to make the bot recognize the client’s phrase regardless of the word order in it.
The {I like fish *}
template will work for any phrase that contains all of the words “І”, “like”, “fish”, and any two to three words regardless of their order. For example, this template will work for “I like fish”, “I don’t like fish”, “I like fish very much”, etc.
Option
Use the square brackets if a specific word can be used but is not required.
For example, for * [small] cat
both “a cat” and “a small cat” will work.
Entity
To specify an entity in the client’s phrase, write the entity in a template with the $
sign before its name.
For example, if you create a dictionary containing the list of cities and name it CITY
, you can use the following syntax: * live * $CITY *
will accept “I live in Berlin”.
The bot will recognize the $CITY
entity, create a $CITY
variable, and put the city name into it.
Variable
If you expect the client to write several entities from the same dictionary, you need to get several variables. Use ::
to create several variables for different entities.
For example, * $CITY::From * $CITY::To *
will accept “Berlin Stockholm” or “Tickets Paris Istanbul”.
Pattern combinations
You can use different patterns in any combinations.
For example, if you expect the client to buy a ticket to any city, you can write a template as follows:
{(order/~ticket/~flight/buy) * $DATETIME * [$CITY]}