article by Grant Ronald, March 2019

 

One of the key features of a chatbot or digital assistant is understanding and extracting entity values from a user utterance. These entity values are critical pieces of information which are usually used as data for backend systems or acted upon within a conversation. 

However, the nature of entities and user input is that you don’t always know how many entity values you are likely to get, if in fact any at all. In this article I’ll show how you can introspect the various entities within an entity list, and then access each of the entity values regardless of how many entity values the user says.

The Use Case

Let’s focus on a holiday booking use case where we have a value list entity each for Cities and Countries.  These are combined into an entity list called Places (which can either be a list of cities or countries you may want to visit).

Below image shows the entities created for this example. Note the Places entity to be of type Entity list. An entity list is resolved if one of its contained entities has a value. If all entities can be resolved from the user input, then all entities have values assigned.

And that leads us to the question: How to access all resolved city and country information in the Places entity using the easiest possible way?

So, the user might say “I would like a long weekend away in London, or Paris, maybe Rome or may even consider Spain”. The skill developer would then like to be able to access the individual values for Cities, Countries and the Places.  And of course, we also have to handle the case where an entity value can be null.

The Solution

The solution itself is actually quite elegant: Using the Apache FreeMarker <#if> directive , we first of all check whether the array of entity values referenced by iResult.value.entityMatches[‘EntityName’] is empty or not.  If it is not empty then we use an Apache Freemarker <#list> directive to iterate over and print the values in the array.  Note that the <#list> directive in the example uses "text" as a variable to hold the value of the current item in the array it iterates. 

The below code has two dialog flow states defined: The first state prints all values in the Places entity, while the second looks for countries and the last one for cities. All three use similar Apache FreeMarker expressions

 

The result printed to the embedded tester in Oracle Digital Assistant is shown in the image below. Of course, instead of printing, you can also process the values in the entity arrays. 

 

Related Content

TechExchange – Using Apache Freemarker Expression in Oracle Intelligent Bots

TechExchange – Building Smart Value Lists from Entities

TechExchange Quick-Tip: Printing Multi-Line Text Messages from an Output component

TechExchange Quick-Tip: Dynamically and Conditionally Reduce the Number of Items Displayed in a List

Author