$caila.checkVocabulary
Checks every word from the argument array for belonging to the vocabulary of the specified NLU engine.
Syntax
The method accepts an array of objects with the following properties:
Key | Description | Allowed values | Default value |
---|---|---|---|
word | The word to be checked. | An arbitrary string. | — |
lang | The language that the word belongs to. | en — English. ru — Russian. | The project NLU language. |
engine | The engine that will perform the check. | aot — the engine based on the АОТ service. pymorphy — the engine based on the pymorphy2 library. | aot . |
caution
The
pymorphy
engine does not support English.- ECMAScript 5
- ECMAScript 6
$caila.checkVocabulary([
{word: "technology", lang: "en"},
{word: "технология", lang: "ru", engine: "pymorphy"},
{word: "zxcvbnm,./"}
]); // => [true, true, false]
In the ECMAScript 6 runtime, the method is asynchronous:
await $caila.checkVocabulary([
{word: "technology", lang: "en"},
{word: "технология", lang: "ru", engine: "pymorphy"},
{word: "zxcvbnm,./"}
]); // => [true, true, false]
How to use
An example use of this method is to check whether unrecognized user requests contain at least one vocabulary word. If they don’t, such requests may be treated as spam.
- ECMAScript 5
- ECMAScript 6
state: CatchAll
event!: noMatch
script:
# $parseTree.words is an array of all words contained within the request.
# Convert them from strings to objects having the required format.
var words = $parseTree.words.map(function(string) {
return {word: string};
});
# Check each word whether it belongs to the language vocabulary.
var wordsInVocab = $caila.checkVocabulary(words);
# Increment the counter of unrecognized requests
# only if at least one word was found in the vocabulary.
if (wordsInVocab.indexOf(true) > -1) {
$session.catchAllCounter = $session.catchAllCounter + 1 || 1;
}
# Transfer to the agent when the counter exceeds the threshold.
if: $session.catchAllCounter > 3
go!: /Switch
random:
a: I’m sorry, I didn’t catch that. Could you repeat, please?
a: I didn’t quite get it. Would you mind repeating that for me?
a: Could you say that again? I can’t hear you very well.
state: CatchAll
event!: noMatch
scriptEs6:
# $parseTree.words is an array of all words contained within the request.
# Convert them from strings to objects having the required format.
var words = $parseTree.words.map(function(string) {
return {word: string};
});
# Check each word whether it belongs to the language vocabulary.
var wordsInVocab = await $caila.checkVocabulary(words);
# Increment the counter of unrecognized requests
# only if at least one word was found in the vocabulary.
if (wordsInVocab.indexOf(true) > -1) {
$session.catchAllCounter = $session.catchAllCounter + 1 || 1;
}
# Transfer to the agent when the counter exceeds the threshold.
if: $session.catchAllCounter > 3
go!: /Switch
random:
a: I’m sorry, I didn’t catch that. Could you repeat, please?
a: I didn’t quite get it. Would you mind repeating that for me?
a: Could you say that again? I can’t hear you very well.