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 Condition Match Requirement - 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

Condition syntax introduction

The most common elements that make up a language condition are:

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


Let's dissect this language condition.

The language objects used in the example above are:

    This 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'
    This is also a reference to a Lexical Language Object. In this case, the language object contains baby/babies/baby's/babies'
    This 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 conditions

It is important to acknowledge the intent before writing conditions 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 Object Condition Matches Does not match
cat my cat my cats
cat/cats my cat
two cats
my kitten
%CAT.NN.LEX cat/cats/cat's/cats' my cat
two cats
my kitten
two kittens
one dog
two kittens
one dog
a dragon

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 conditions?

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

  • Conditions can be written much faster
  • Conditions 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 Condition Match Requirement and uses this language condition: (%CAN_I_BRING.PHR + %ANIMALS_PETS.LIST + %ONBOARD.ADJV.SYN)

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:

Component Description
Operators The 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 objects As 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.
Annotations Annotations 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 conditions Groovy 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 scripts A 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.

Setting an 'unused words' limit

Normally, a language condition only specifies which words must be present in an input. There may be other words in the input, not accounted for by the condition, and the input will still match the condition. Let's take a simplistic condition like what + date + is + it. This condition will match both 'What date is it?' and 'What date is it tomorrow?'

Sometimes, however, we want a condition to be very exact and not match if the user's input contains words that were not specified in the condition at all. With 'Limit unused words', restrictions can be added on how many words besides those specified in the condition may be present in the user input.

Limit unused words

More details on how to work with unused words can be found in the Condition Syntax Reference and an example usage is illustrated on the create a custom order group page.

Draft a condition

Conditions can be coded manually, or Teneo Studio can automatically generate a condition with the 'Draft Condition' function. This drafted condition is based on the positive examples for that node.


An automatically generated condition is always based on the full text of all the examples entered. Therefore it is best to be brief in the examples, and only use words that are relevant to understand what the end user wants.

An automatically generated condition is guaranteed to match the examples entered, but is not necessarily the best condition possible. Perhaps it is a bit too wide or a bit too exact for the current use case? Perhaps it can be made more efficient or easier to maintain? After the condition is generated, always look for potential areas of improvement.

Coding language conditions manually

If preferred, language conditions 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 condition. Here we must ask ourselves, is one single condition enough to fit all variations or do we need multiple conditions? Are we covering enough synonyms and enough different sentence structures?

Teneo Studio offers useful suggestions for cases where we write language conditions 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 condition 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.


Was this page helpful?