Used words
When Teneo matches a Teneo Linguistic Modeling Language (TLML) condition against user input it also keeps track of the words of the input that are involved in the match. These words are called _USED_WORDS in Teneo, and they can be referred to from listeners and from attached scripts.
Used words in Listeners
Listeners in Teneo consist of two parts: a TLML Syntax part and a Execution Script part. Every word that matches the expression of the Syntax condition part is stored in the special _USED_WORDS variable from where they can be used for further processing. An example is given below.
Used words in Attached Scripts
When used in attached scripts, the _USED_WORDS variable contains the words that matched the part of the condition that the script has been attached to. An example is given below, where _USED_WORDS is used in a script attached to the language object COFFEES_SERVED.NN.LIST.
Scripting API
Teneo features a scripting API method called _.getUsedWords() that allows access to different stages of the input processing. This means that you can access different versions of the user input, depending on the parameter you pass. You may access the user utterance as it was (_.ORIGINAL), a simplified version of it (_.SIMPLIFIED), or its final version after having passed the whole input processing pipeline (_.FINAL).
Method | Value |
---|---|
_.getUsedWords(_.ORIGINAL) | Returns the words spelled exactly as given in the input text, without any further word processing. |
_.getUsedWords(_.SIMPLIFIED) | Returns the simplified words of the input text. |
_.getUsedWords(_.FINAL) | Returns the words of the input text after all preprocessing steps (e.g. simplification, auto-correction, compound splitting, etc.) |
In contrast to the _USED_WORDS variable which stores the user input as one string, these methods return the user input as a list of strings. For example the sentence "I want to order a cappuccino" is returned as ["I", "want", "to", "order", "a", "cappuccino"]. If you want them to look good in your output you thus have to add a .join(" ") at the end of the call which will join everything into one string separated with whitespaces:
groovy
1_.getUsedWords(_.ORIGINAL).join(" ")
2
Optionality and _USED_WORDS
Teneo features two ways of expressing optional words in an input: the optional match option (:O) (for example: I >> (really):O >> like >> you) and the maybe operator (~) (for example: (how+are+you) ~(doing/feeling/dear)). If the user input matches an optional part of a Syntax Condition, the words of this match are also included in _USED_WORDS.