Optimize language conditions

Earlier on we have seen examples of how to semi-automatically create language conditions based on positive example inputs. For example, we created a syntax condition that can handle conversations like the following:

User: Can I have one of those?
Bot: Ok, a Cappuccino will be ready for pickup in 5 minutes.

However, as soon as you slightly change the question, you will get a wrong answer

User: Can I have 1 of those?
Bot: I am sorry, can you re-phrase your question?

In the following, we will shorten the language condition while at the same time broaden its coverage. After having investigated what went wrong in the second part of the example conversation above, we improve the language condition by following two strategies:

  • Recombining language objects
  • Exchanging language objects

Having a closer look at the language condition

This is the language condition that has automatically been created from our positive examples:

(
    (%I.FW.LEX &^ %WANT.VB.LEX &^ (one/%IT.FW.LEX))
    /
    (%I_WILL.PHR &^ %GO_FOR.VB.MUL &^ %IT.FW.SYN) 
)^{ orderedCoffeeType = coffeeTypeInFocus }

The reason why the question "Can I have 1 of those?" did not trigger this flow is that '1' is not among the words listed in the condition. We will thus in recombine the language objects so that the different phrases for asking about the pricing are combined with the different ways of expressing "one" or "1".

Recombination of language objects

We start by updating each line of the language condition to make it match on both 'one' and '1'. We do this by replacing each occurrence of 'one' with a language object called '%ONE.FW.LEX', as illustrated below:

(
    (%I.FW.LEX &^ %WANT.VB.LEX &^ (%ONE.FW:LEX/%IT.FW.LEX))
    /
    (%I_WILL.PHR >> %GO_FOR.VB.MUL >> %IT.FW.SYN) 
)^{ orderedCoffeeType = coffeeTypeInFocus }

You may have noticed that we replaced the &^ operator between I_WILL.PHR and GO_FOR.VB.MUL with the operator >>. This latter operator is called 'directly followed by' and does not allow for intervening words. For more information on the condition syntax language, go and have a look at the reference page.

Strictly speaking, our problem is now solved. However, we can go one step further. The first line of our condition can be replaced with a phrase language object:

(
    (%I_WANT.PHR &^ (%ONE.FW.LEX/%IT.FW.LEX))
    /
    (%I_WILL.PHR >> %GO_FOR.VB.MUL >> %IT.FW.SYN) 
)^{ orderedCoffeeType = coffeeTypeInFocus }

The &^ operator matches regardless of the word order in the user input. Thus, we can move IT.FW.LEX to the first part of the condition without losing coverage.

That's it. What a nice and powerful language condition we now have created!

Exchange language objects

We now have a much more robust language condition than before. However, there are still some inputs like 'I want that' that are not yet covered by this condition. So let's broaden the coverage of the condition a bit.

As we can see, the condition currently uses the lexical language object IT.FW.LEX. Lexical objects only cover inflections of a word. Perhaps there is another language object we can use that covers synonyms. To do that you can try this:

  1. Select %IT.FW.LEX and replace it with the text it
  2. Hit Ctrl + Space
  3. A list with language objects matching 'it' appears. One of them is IT.FW.SYN and if you hover over it you will see it covers many synonyms of 'it' including 'that'.
  4. Now go ahead and replace '%%IT.FW.LEX' with %IT.FW.SYNin your condition.
  5. Hit 'Save'.

Your final condition should now look like this:

(
    (%I_WANT.PHR &^ (%ONE.FW.LEX/%IT.FW.SYN))
    /
    (%I_WILL.PHR >> %GO_FOR.VB.MUL >> %IT.FW.SYN) 
)^{ orderedCoffeeType = coffeeTypeInFocus }

As you have noticed you can type words (and even parts of sentences) straight into the condition editor and ask Teneo for language objects matching those words. This auto-complete function is very handy if you have a bit of an idea which words you would like to cover and explore what is covered by the Teneo Language Resources. You can read more about it here: How to find language objects. Once you get a bit more experienced, you might know common language objects by heart and include them directly.

Was this page helpful?