Teneo Developers

Language conditions

Teneo can use language conditions to verify if an input of a user matches certain linguistic criteria. For example, a language condition used in a syntax trigger of a flow makes sure the flow is triggered when the user's input matches the criteria in the language condition. Or if a transition inside a flow contains a language condition, then Teneo will only traverse the transition when the input matches the language condition of the transition.

Examples of language conditions in use can be seen on these pages:

  • Triggers with TLML Syntax Match - A flow will be executed if the user input matched the language condition in the trigger of the flow
  • Transitions - A transition in a flow is only traversed if the user input matched the condition in the transition
  • Listeners - The 'operation' script of a listener is only executed if the user input matched the condition in the listener

TLML Syntax introduction

The most common elements that make up a Teneo Linguistic Modeling Language (TLML) condition are:

For example, the following TLML Syntax contains 3 language objects and 2 operators:



Let's dissect this language condition.

The language objects used in the example above are:

  • %BAGGAGE.NN.LEXThis is a reference to a Lexical Language Object (note the extension .LEX) in the Teneo Lexical Resources. Lexical language objects just cover the different inflections of a word, as well as spelling and regional variations. In this case, the language object contains baggage/baggages/baggage's/baggages'
  • %BABY.NN.LEXThis is also a reference to a Lexical Language Object. In this case, the language object contains baby/babies/baby's/babies'
  • %CHILD.NN.SYNThis is a reference to a Synonym (SYN) object. Synonym objects cover synonyms of a word, usually by referencing other language objects. In this case, the language object contains (%CHILD.NN.LEX / %KID.NN.LEX / %JUVENILE.NN.LEX / %MINOR.NN.LEX / %OFFSPRING.NN.LEX / %INFANT.NN.SYN) (note that the contents of language objects are language conditions too!)

The example condition contains the following operators:

  • & - This is the AND operator. Both the expression before and after the AND operator should match for the condition to be true, regardless of the word order in the user input.
  • / - This is the OR operator. Either the expression before or after OR operator needs to match for the condition to be true.

In the example condition above we also use parentheses ( ). Parentheses are used to group expressions belonging together. In the example above, this means that the condition will only match if the input contains the word 'baggage' and the word 'baby' or if the input contains the word 'baggage' and a synonym of 'child'.

Based on this information we can determine that this condition will match on:

  • 'How much baggage can I bring for my baby?'
  • 'What is the baggage allowance for a child?'
  • 'Can a minor bring baggage on the plane?'

All inputs above contain at least the word 'baby' or a synonym of 'child' and they also contain the word 'baggage'.

The condition above will not match on the following inputs:

  • 'What is the luggage allowance for a child?'
  • 'Can an adult bring baggage on the plane?'
  • 'What is the weather like in Barcelona?'

Language objects in TLML Syntax

It is important to acknowledge the intent before writing TLML Syntax in a flow. What is the purpose of this flow, what do we want it to trigger and what do we want to avoid? Depending on the language objects mentioned, the flow can become stronger or weaker. Therefore it is important to know when to use which language object.

The following demonstrates an example with the word 'cat' as a starting point together with the different levels.

Language ObjectConditionMatchesDoes not match
catmy catmy catskitten
cat/catsmy cat two catsmy kitten
%CAT.NN.LEXcat/cats/cat's/cats'my cattwo catsmy kitten

As you can see in the examples above (CAT.NN.SYN and ANIMALS_PETS.LIST), the language condition of a language object can refer to other language objects. This makes it very easy to create language objects that recognize complex linguistic structures.

Why use language objects in your TLML Syntax?

There are several advantages to using language objects in your TLML Syntax, including:

  • TLML Syntax can be written much faster
  • TLML Syntax become more intelligent
  • Language objects are re-usable
  • Many language objects are available out of the box (included in the Teneo Lexical Resources for the following Languages)!

Consider an example use case in which we want to create a linguistic match requirement that fires on questions from users who want to know if they can bring their pet on board of an aircraft.

Possible inputs may include:
• Can I bring my dog ...
• Is it OK if I take my cat ...
• Would you mind if I carry my chihuahua ...

In this case, we could create a flow in which the trigger has a TLML Syntax Match Requirement and uses this condition:



Condition components

The introduction above highlights a few of the core elements of a language condition, but there are many more components that can be used when creating language conditions. The following list contains the elements that can be used and links to pages with more details:

OperatorsThe example above already introduced two operators, but to get precise control on what to match there are many more operators that can be used. More details can be found in the Condition Syntax Reference.
Language objectsAs outlined above, language objects capture words, synonyms or various ways of expressing the same (partial) intent. More details can be found on the Language Objects page. Teneo provides Lexical Resources that contain many pre-defined language objects.
AnnotationsAnnotations can be considered 'labels' that are attached to inputs. They are mostly attached to an input using machine learned models. Annotations can be used in language conditions in a similar way as language objects. More information on this can be found on the Annotations page.
Script conditionsGroovy scripts can be used in conditions too. For a Script condition to be fulfilled, the result of the expression has to be true. More details can be found in the script-condition paragraph of the Condition Syntax Reference.
Attached scriptsA language condition's primary goal is to make sure an input matches certain linguistic criteria. However, attached scripts can also be included in a language condition. The purpose of attached scripts in a condition is not so much to make sure that an input matches certain criteria, but to extract information from an input. An input may contain a city or product name that we may want to remember and use, and attached scripts can be used to extract them. More details can be found on the attached scripts page.

Coding TLML Syntax manually

If preferred, TLML Syntax can be created from scratch as well. In this case, the first step is to make sure there is a clear idea of what user inputs should match with the syntax. Here we must ask ourselves, is one single syntax enough to fit all variations or do we need multiple pieces of syntax? Are we covering enough synonyms and enough different sentence structures?

Teneo Studio offers useful suggestions for cases where we write syntax from scratch. This way, there's no need to memorize how to write every single language object or other element in the condition. To see these suggestions, simply type text into the syntax text field, select all or some of that text, and hit Ctrl + Space. A list of suggestions will pop up, as seen in the following image.