Extract data with entities

This page describes how to extract parameter values (entity 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
  4. Click SAVE.

Dialogflow automatically detects parameters in your Training phrases that are included in system entities. System entities are entity sets provided by DIalogflow to cover most expected values for things like location, color, and dates.

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

  • The parameter is optional (not required).
  • The name language (automatically resolved for system entities).
  • The entity this entry corresponds to (in this case its the system entity @sys.language.
  • The value of $language (automatically resolved).
  • The parameter is not a list.

Use parameter data in a response

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!

In the simulator on the right, query your agent with "I know Russian".

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

In most cases you'll have specific information you need to gather from users, that isn't covered by Dialogflow's system entities. Developer entities are sets of values and synonyms you provide.

To create an entity, follow these steps:

  1. Click on the plus add next to Entities in the left menu.
  2. Enter "ProgrammingLanguage" for the name of the entity.
  3. Click in the left 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 has to have the following:

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

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

    The programming languages in the training phrases should be automatically annotated. This adds the ProgrammingLanguage parameter to the table.

  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

You might want to check out: