Extract data with entities

This page describes how to extract data from a user's query.

Add parameters to your intents

Parameters are important and relevant words or phrases in a user's query that are extracted so your agent can provide a proper response. You'll create a new intent with parameters for spoken and programming languages to explore how these can match specific intents and be included in your responses.

  1. Create a new intent by clicking on the plus add next to Intents in the left menu.

  2. Name the intent "Languages" at the top of the intent page.

  3. Add the following as Training phrases:

    • I know English
    • I speak French
    • I know how to write in German

Dialogflow automatically detects known parameters in your Training phrases and creates them for you.

Below the Training phrases section, Dialogflow fills out the parameter table with the information it gathered:

  • The parameter is optional (not required)
  • named language
  • corresponds to the system entity type @sys.language
  • has the value of $language
  • is not a list

Use parameter data

The value of a parameter can be used in your responses. In this case, you can use $language in your responses and it will be replaced with the language specified in the query to your agent.

In the Responses section, add the following response and click the Save button:

  • Wow! I didn't know you knew $language

Try it out!

Now, query your agent with "I know Russian" in the simulator in the right panel.

You can see in the bottom of the simulator output that Dialogflow correctly extracted the language parameter with the value "Russian" from the query. In the response, you can see "Russian" was correctly inserted where the parameter value was used. Parameters can also be handled in your fulfillment. This is covered later in Integrating other services with fulfillment.

Create your own entities

You can also create your own entities, which function similarly to Dialogflow's system entities.

To create an entity:

  1. Click on the plus add next to Entities in the left menu.

  2. Enter "ProgrammingLanguage" for the name of the entity.

  3. Click on the text field and add the following entries:

    • JavaScript
    • Java
    • Python
  4. When you enter an entry, pressing tab moves your cursor into the synonym field. Add the following synonyms for each entry:

    Entry Synonym
    Javascript js, ECMAScript
    Python py
  5. Click the Save button.

Each entity type has to have the following:

  • a name to define the category (ProgrammingLanguage)
  • one or more entries (JavaScript)
  • one or more synonyms (js, ECMAScript)

Dialogflow can handle simple things like plurality and capitalization, but make sure to add all possible synonyms for your entries. The more you add, the better your agent can determine your entities.

Add your new entities

Now that we've defined our entity for programming languages, add Training Phrases to the "Languages" intent:

  1. Click on Intents in the left menu, and then click on the "Languages" intent.

  2. Add the following as Training phrases:

    • I know javascript
    • I know how to code in Java

    You should see the programming languages automatically annotated in the Training phrases you entered. This adds the ProgrammingLanguage parameter to the table, which is below the Training phrases section.

  3. In the Responses section, add $ProgrammingLanguage is cool and then click the Save button.

Try it out!

Now, query your agent with the new entity. In the simulator, type I know how to code in py and press enter.

You can see that Dialogflow correctly extracted the entity py, identified it as the Python entity, and inserted the value in the response.

Next steps

If you have any questions or thoughts, let us know on the Dialogflow Google Plus Community. We'd love to hear from you!

You might also want to check out: