How to use LUIS entities

Another big advantage with LUIS^Teneo is the use of entities. Entities can capture and pass important information from the user input. LUIS provides many prebuilt entities covering common fields like person name, geography info, etc. A user can also create their own entities in LUIS. This section will show how to use LUIS entities in Teneo Studio.

We'll continue with the 'What can I get for 20 dollar?' flow created in the last page to capture the amount of money a user mentioned and calculate how many cups of coffee can user get.

This is how such a conversation could go about:

User: What can I get for 20 dollars?
Bot: For 20 dollar you can get 10 cups of coffee.

User: What can I get for 40 dollars?
Bot: For 40 dollar you can get 20 cups of coffee.

To achieve this we will do the following:

  • Add a prebuilt entity in LUIS
  • Create a custom entity on Teneo
  • Create a flow variable
  • Add a data actions
  • Add a script node
  • Use a flow variable in the answer text

This is what your flow will look like: Final Version Of Flow

Add a prebuilt LUIS Entity

We will start off by adding a prebuilt entity inside our LUIS application,

  1. While inside your LUIS application, select 'Entities' located on the sidebar to the left.
  2. Select 'Add prebuilt entity' and search for money.
  3. Select 'money' and press 'Done'. This will add the selected entity to our LUIS application.
  4. Press 'Publish' at the top right corner. This so Teneo can retrieve it.

The entity page should look like this when you are done: LUIS Entity Page

Create a 'Language Objects' folder

Before we create our entities, it might be a good idea to create a folder that we can use to store them. This is not required, but as a solution grows, folders help to structure your Teneo assets. To create the folder, proceed as follows:

  1. Make sure none of the folders on the left are selected, by clicking in the white area below the folders in the 'Explore' section.
  2. Click the 'Folder' icon in the 'New' group in the Ribbon.
  3. Give your folder a name, for example Language Objects and hit Enter.

Create a Entity

Now its time to translate the values stores from our previously created LUIS entity inside a Teneo entity.

  1. In your main solution window, select the 'Language Objects' folder and click 'Entity' in the 'New' section of the Ribbon. This will create a new entity in the selected folder.
  2. Call the entity LUIS_MONEY (the type .ENTITY is automatically defined).
  3. Use the left arrow on the top to get to the HOME tab of the entity.
  4. Select the dropdown menu under 'Add Variable' in the 'Variables' section followed up with 'Add Script Variable'.
  5. Name the script variable luisAmount.
  6. Add one more 'Script Variable' but this time call it luisValue.
  7. Select the entry and copy the following table onto the clipboard followed up with 'First row is variable names'.
Entry luisAmount luisValue
%$LUIS_MONEY.ENTITY lob.number _USED_WORDS

The end result should look like this: script_explained

Add a flow variable

To be able to store the amount and currency mentioned by the user, we need to create two flow variables:

  1. Open 'What can I get for 20 dollars?' in edit mode.
  2. Click on the tab 'FLOW' in the top left corner of the flow window.
  3. Choose 'Variables' in the purple bar on the left.
  4. Click 'Add' in the top right of the window.
  5. Name the variable amount by replacing the word 'Variable 1'.
  6. We want to initialize this variable zero as default value, so in the text box below add 0.
  7. Add one more variable and call it value with "" as default value.

Pick up the entity using data actions

Now that we have the trigger in place it is time to pick up the amount and currency that the user mentioned. We will do so by using data actions:

  1. Go back by pressing the arrow in the top left corner and select the trigger, this will open the trigger configuration panel to the right.
  2. In the panel on the right, go to 'Data Actions', click 'Add' and hover over 'Entity' from the drop-down menu. When on the little triangle, all available entities will appear. Paste in LUIS_MONEY.
  3. Select the 'Add Mapping' button.
  4. The 'Source' field denotes the value of the NLU variable of the entity 'LUIS_MONEY' that we want to store. In our case 'luisAmount'.
  5. The 'Target' field denotes the name of the variable where the extracted value is to be stored. In our case 'amount'.
  6. Repeat the previous steps and add one more mapping for the source 'luisValue' to the target 'value'

Add a script node

With nothing else in the flow marked, click the 'Script' icon in the ribbon. This will add an empty script node to your flow. Give it a name that explains what the script does, like Calculate amount.

Populate the script node

We have added the script node, but it is still empty. Now we'll need to add the script that calculates the number of cups it can afford. Select the script node in your flow, open the 'Script Action' tab on the right sight of the screen and paste the following code into the script node:

amount = amount / 2

Put the script node in its place

Currently, our script node is dangling and not connected to any of the other elements in the flow. However, we want our script to be executed immediately after the flow is triggered, and right before the output is shown to the user. To achieve this we need to follow these steps:

  1. Select the script node.
  2. In the ribbon choose 'Set start node'. This points the trigger straight to the script node.
  3. Draw a line from the script node to the output node.

Configure the output node

The only thing that remains to be done now, is to configure the output node to summarize the flow.

  1. Select the output node '10 cups of coffee'
  2. Change the answer to For ${value} you can get ${amount} cups of coffee.
  3. Change the output node name to ... Cups of coffee!.
  4. Hit 'Save'.

Try it out

That's it. Now go to Try-out and give it a go! The answer should change depending on the amount provided.

User: What can I get for 20 dollars?
Bot: For 20 dollar you can get 10 cups of coffee.

User: What can I get for 40 dollars?
Bot: For 40 dollar you can get 20 cups of coffee.

Where to go next?

Now that we know how to use LUIS^Teneo its time to learn more about, Deploy your bot where you'll find documentation on our SDK's and example connectors for platforms like Microsoft Bot Framework, Slack, Facebook Messenger and Google Assistant.

Was this page helpful?