6 Entities
While intents map words and phrases to a specific action, entities add context to the intent itself. They help to describe the intent more fully and enable your bot to complete a user request. The OrderPizza intent, for example, describes a user request, but only in general terms. To fill in the specifics, this intent is augmented by the PizzaSize entity, which identifies values like large, medium, and small from the user input. There are two types of entities, both of which you can declare as variables in the dialog flow: built-in entities that we provide for you and custom entities, which you can add on your own.
Built-In Entities
Whenever you define a variable as an entity in your dialog flow, be sure to match the entity name and letter case exactly. In other words, you’ll get a validation error if you enter confirm: "YESNO"
instead of confirm: “YES_NO”
.
Simple Entities
Entity Name | Content Identified | Examples |
---|---|---|
NUMBER | Matches ordinal and cardinal numbers |
|
An email address—The NLU system can recognize email addresses that have combinations of letters (a-z), numbers (0–9), underscores (_) and plus (+) and minus (-) signs before the at symbol (@). The address can’t have a dot (.) immediately after the @ symbol, but the domain name (which is comprised of letters and numbers only), must include the dot. | ragnar.smith@example.com | |
ADDRESS | An address or location-related entities |
200 Oracle Parkway, Redwood Shores, CA |
YES_NO | Detects a “yes” or “no”. | Yes, Yeah, no |
Complex Entities
Unlike simple entities, complex entities extract content using properties, each of which recognizes a specific value. When you train and test your intents, you can see these properties in the Tester. The JSON output that’s returned by the NLU Engine shows these entities along with the value that they’ve identified from the user input.
Description of the illustration entity_properties.png
When you define a variable in your dialog flow that uses a complex entity, you will need to include these properties in the value expression. See Accessing Variable Values with Apache FreeMarker FTL.
Entity Name | Content Extracted | Examples | Properties (Referenced in Value Expressions) | Example NLU Engine Response |
---|---|---|---|---|
DATE | An absolute or relative date |
|
|
|
TIME | A specific time | 2:30 pm |
|
|
DURATION | The amount of time between the two endpoint of a time interval |
|
|
|
SET | Recurring time periods. |
|
|
|
CURRENCY | Representations of money |
|
|
|
PHONE NUMBER | A phone number—The NLU Engine recognizes phone numbers that have seven or more digits (it can’t recognize any phone number with fewer digits). All country codes need to be prefixed with a plus sign (+), except for the United States of America ( where the plus sign is optional). The various parts of the phone number (the area code, prefix, and line number), can be separated by dots (.), dashes (-), or spaces. If there are multiple phone numbers entered in the user input, then the NLU Engine can recognize them when they’re separated by commas. It can’t recognize different phone numbers if they’re separated by dots, dashes or spaces. |
|
|
|
URL | A URL—This entity can extract IPv4 addresses, Web URLs, deep links (http://example.com/path/page ), file paths, and mailto URIs. If the user input specifies login credentials, then it must also include the protocol. Otherwise, the protocol isn’t required.
|
http://example.com |
|
|
Custom Entities
Because the built-in entities extract generic information, they can be used in a wide variety of bots. Custom entities, on the other hand, have a narrower application. Like the FinancialBot’s AccountType entity that enables various banking transactions by checking the user input for keywords like checking, savings, and credit cards, they’re tailored to the particular actions that your bot performs.
Custom Entity Types
Entity Type | Description |
---|---|
Derived | A derived entity is the child of a built-in entity or another entity that you define. You base this relationship on prepositional phrases (the “to” and “from” in utterances like I want to go from Boston to Dallas or Transfer money from checking to savings). |
Value list | An entity based on a list of predetermined values, like menu items or the FinancialBot’s checking, credit, and card options that are output by the System.List component. You can optimize the entity’s ability to extract user input by defining synonyms. These can include abbreviations, slang terms, and common misspellings. Synonym values are not case-sensitive: USA and usa, for example, are considered the same value.
|
Entity list | A super set of entities. Using a travel bot as an example, you could fold the entities that you’ve already defined that extract values like airport codes, cities, and airport names into a single entity called Destination. By doing so, you would enable your bot to respond to user input that uses airport codes, airport names, and cities interchangeably. So when a user enters “I want to go to from JFK to San Francisco,” the Destination entity detects the departure point using the airport code entities and the destination using the cities entity. |
Regular Expression | Resolves an entity using a regular expression (regex). Using regular expressions lets your bot identify pre-defined patterns in user inputs, like ticket numbers. |
Create Entities
- Click Entities () in the side navbar.
- Click Add Entity and then enter the name.
- In the Configuration section, choose entity type from the list.
- Value List—Define a set of values for an entity that’s defined by predetermined terms.
Note:
Adding punctuation or special characters to the same term creates different values: the entity can't match USA from the user input with either USA? or USA!, or cafe with café. To match a value regardless of case or punctuation, create a regular expression entity. You can define it using syntax like(\w+)
- Entity List—A super set of entities.
- Derived Entities—A derived entity is the child of another entity (either built-in or custom) that’s modified by a preposition that you add using the Preceding Phrase or Following Phrase rules.
Important:
Derived entities can’t be parent entities. And because the NLU Engine detects derived entities only after it detects all of the other types of entities, you can’t add derived entities as members of an entities list. Only custom or the built-in entities can belong to a list. - Regular Expression—Enter the regular expression (regex) pattern. Unlike the other entity types, regex-based entities don’t use NLP because the matching is strictly pattern-based.
For example this expression,(?<=one\s).*(?=\sthree)
returns the word that’s between “one” and “three” in the user input.
- Value List—Define a set of values for an entity that’s defined by predetermined terms.
- Next steps:
Import Value List Entities from a CSV File
entity
, value
, and synonyms
. For example:entity,value,synonyms
CheeseType,Mozzarella,Mozarela:Mozzarela
CheeseType,Provolone,
CheeseType,Gouda,
CheeseType,Cheddar,
PizzaSize,Large
PizzaSize,Medium
PizzaSize,Small
-
Click Entities () in the side navbar.
-
Click More, choose Import Value list entities, and then select the
.csv
file from your local system. -
Add the entity or entities to an intent (or to an entity list and then to an intent).