article by Frank Nimphius, may 2018
Update note:
Oracle Intelligent Bots has been rebranded Oracle Digital Assistant to better describe its capabilities beyond a standard chatbot. To learn more, visit cloud.oracle.com/digital-assistant
Using Apache Freemarker Template expressions in Oracle Intelligent Bots makes it is easy to determine whether a user sentence contains a specific entity value or not.
The starting point for this, as usual when language recognition is required, is the System.Intent component that fills a variable of type nlpresult (typically this variable is called "iResult"). The iResult variable then holds all values of a given entity type that is contained in the user sentence.
In the example, I am using an order for Drinks to tell if it contains Coffee. The Apache FreeMarker expression to detect this drink is
${iResult.value.entityMatches['Drinks']?seq_contains('Coffee')?then('Y', 'N')}
Note that the boolean value true or false are returned as "Y" for when coffee is contained in the order and "N" if it is not. Please find below the complete OBotML listing for this use case.
context:
variables:
iResult: "nlpresult"
containsDrink: "string"
userMessage: "string"
states:
askForOrder:
component: "System.Text"
properties:
prompt: "Please enter your order for drinks"
variable: "userMessage"
intent:
component: "System.Intent"
properties:
variable: "iResult"
sourceVariable: "userMessage"
confidenceThreshold: 0.4
confidenceWinMargin: 0.0
optionsPrompt: "Do you want to"
transitions:
actions:
Order: "findCoffeeInEntity"
unresolvedIntent: "unresolvedState"
findCoffeeInEntity:
component: "System.SetVariable"
properties:
variable: "containsDrink"
value: "${iResult.value.entityMatches['Drinks']?seq_contains('Coffee')?then('Y', 'N')}"
isCoffee:
component: "System.ConditionEquals"
properties:
variable: "containsDrink"
value: "Y"
transitions:
actions:
equal: "messageIfContains"
notequal: "messageIfNotContains"
messageIfContains:
component: "System.Output"
properties:
text: "Your order contains coffee"
keepTurn: false
transitions:
return: "done"
messageIfNotContains:
component: "System.Output"
properties:
text: "Your order does not contain coffee."
keepTurn: false
transitions:
return: "done"
unresolvedState:
component: "System.Output"
properties:
text: "Sorry, we did not seem to find what you where asking for. Please try again."
keepTurn: true
transitions:
next: "askForOrder"
The code above uses an intermediary step, which is to write the "Y" or "N" character to a context variable. In a System.ConditionEquals component I then conditionally determine the next state to navigate too.
The Drinks entity is defined as a list of values and is shown in the image below. The entity is associated with the Order entity.
At runtime, the outcome of the user-bot conversation looks as shown below
Related Content:
TechExchange – Using Apache Freemarker Expression in Oracle Intelligent Bots
TechExchange: Displaying the Top 3 Runner-Up Intents in case of Unresolved Intent Resolution
TechExchange Quick-Tip: Accessing Attribute Names and Values of a Data Object
TechExchange: How-to create a Star-Rating UI in your Bot Conversation