{"id":18097,"date":"2019-01-28T06:44:05","date_gmt":"2019-01-28T06:44:05","guid":{"rendered":"https:\/\/developer.kore.ai\/v10-1\/?post_type=docs&#038;p=15965"},"modified":"2023-12-12T07:34:12","modified_gmt":"2023-12-12T07:34:12","slug":"working-with-composite-entities","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v10-1\/docs\/bots\/bot-builder-tool\/dialog-task\/working-with-composite-entities\/","title":{"rendered":"Working with Composite Entities"},"content":{"rendered":"<h2><span class=\"ez-toc-section\" id=\"Introduction_Use_Case\"><span style=\"font-weight: 400;\">Introduction &amp; Use Case\u00a0<\/span><\/span><\/h2>\n<p><strong>Composite Entities<\/strong><span style=\"font-weight: 400;\"> help you capture multiple entity values in a user utterance. These multiple entity values are optional and come in any order in the user utterance.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let us consider the below example.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A travel agency receives a typical request, which can be of the form:<\/span><\/p>\n<p><span style=\"color: #808080;\"><em><span style=\"font-weight: 400;\">I am interested in traveling tomorrow from LA to NYC, first class, and I want a window seat.<\/span><\/em><\/span><\/p>\n<p><span style=\"font-weight: 400;\">In such a query, the Virtual Assistant needs to process information such as: travel date, departure city, arrival city, flight class and seat preference, in order to respond to this enquiry.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Each of these multiple values or details come from different independent entities. Composite Entities enable you to combine these independent entities or sub-entities.<\/span><\/p>\n<div class=\"w-separator size_medium with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"How_it_Works\"><span style=\"font-weight: 400;\">How it Works?<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">When a composite entity reaches the dialog flow:<\/span><\/p>\n<ul>\n<li>If the input is received as a JSON object, the input JSON object is added to the Context object under the corresponding entity without any analysis.<\/li>\n<li><span style=\"font-weight: 400;\">If the input is received as a text input<\/span>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">All the possible sub-entities from the defined composite entity patterns are identified.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">All possible instances of those sub-entities are located in the user utterance and the location recorded.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The composite entity patterns are then evaluated to identify the specific pattern that matches the set of sub-entity instances captured.<\/span><\/li>\n<\/ul>\n<p>i.e. the composite entity pattern is not used to identify the sub-entities but to match the entire pattern.<\/li>\n<\/ul>\n<div class=\"w-separator size_medium with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Composite_Entity_Patterns\"><span style=\"font-weight: 400;\">Composite Entity Patterns<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">These patterns help you to establish the relationship between the sub-entities. Sub-entities are included in the composite entity using the @ tag, i.e.,<\/span><span style=\"font-weight: 400;\">@subentity<\/span><span style=\"font-weight: 400;\"> in the composite entity pattern. These sub-entities must be pre-defined and should not be part of the current dialog flow. The sub-entities come from other Dialog Tasks too.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Various patterns like AND, OR, etc,. are built similar to the ones used in defining Entity Patterns (<\/span><a href=\"https:\/\/developer.kore.ai\/v10-1\/docs\/bots\/nlp\/fundamental-meaning\/#Navigate_to_the_Patterns_Tab\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-weight: 400;\">refer here for more<\/span><\/a><span style=\"font-weight: 400;\">).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The Composite Entity values take the form of a JSON object wherein the sub-entities are referenced as properties of that object, i.e. to access a sub-entity value, you can use: <code>{{context.entities.&lt;&lt;composite_entity&gt;&gt;.&lt;&lt;sub_entity&gt;&gt; }}<\/code><\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can access each of the sub-entities using the structure they are defined with, as they are accessed when used independently of the composite entity. For example, if the sub-entity is of the type <\/span><em><span style=\"font-weight: 400;\">Airport<\/span><\/em><span style=\"font-weight: 400;\">, then one can access the airport name as follows: <code><\/code><\/span><span style=\"font-weight: 400;\">{{context.entities.&lt;&lt;composite_entity&gt;&gt;.&lt;&lt;sub_entity&gt;&gt;.AirportName }}<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Create_a_Composite_Entity\"><span style=\"font-weight: 400;\">Create a Composite Entity<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Building a composite entity involves the following steps:<\/span><\/p>\n<ol>\n<li><span style=\"font-weight: 400;\">Create sub-entities<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Establish a relationship between these sub-entities.<\/span>[\/vc_column_text]\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Create_Sub-Entities\"><span style=\"font-weight: 400;\">Create Sub-Entities<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Since the Composite Entity is a combination of other entities, you need to build individual entities in the dialog task. To capture the Flight Information from the above example, you must create sub-entities that capture the required details. Here is a sample mapping of sub-entities for a primary entity called <\/span><em><span style=\"font-weight: 400;\">Flight <\/span><\/em><span style=\"font-weight: 400;\">, for which we create a few sub-entities to capture relevant information:<\/span><\/p>\n<table>\n<thead>\n<tr>\n<th>ENTITY<\/th>\n<th>ENTITY TYPE<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Travel Date<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Date: To capture the travel date from the user utterance. The VA recognizes dates automatically.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Departure City<\/span><\/td>\n<td><span style=\"font-weight: 400;\">List of Items: To capture the name of the departure city\u00a0 from the user utterance. As a developer, you must build this list in the entity.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Arrival City\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">List of Items: To capture the name of the arrival city from the user utterance. As a developer, you must build this list in the entity.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Class\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">List of items: : To capture the flight class from the user utterance. As a developer, you must build this list in the entity.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Seat Preference<\/span><\/td>\n<td><span style=\"font-weight: 400;\">List of items: To capture the seat preference from the user. As a developer, you need to build the list in the entity.\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table style=\"height: 50px; width: 100%; background-color: #fffbea;\" width=\"100%\">\n<tbody>\n<tr style=\"height: 50px;\">\n<td style=\"height: 50px;\" width=\"100%\"><b>Note<\/b><span style=\"font-weight: 400;\">: Sub-entities can only be combined into a composite entity and are recommended not to use for any other purpose in the dialog task. If you are creating sub-entities in the current dialog task, remove all transitions to these sub-entities, so that they are not a part of the dialog task flow.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Define_a_Composite_Entity\"><span style=\"font-weight: 400;\">Define a Composite Entity<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Add a Composite Entity after a relevant node in the dialog task. To make this entity capture multiple entity values, you need to create Composite Patterns. To create, follow the below steps:<\/span><\/p>\n<ol>\n<li><span style=\"font-weight: 400;\">On the Entity window, click the <strong>NLP Properties<\/strong> tab.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">On the <strong>NLP Properties<\/strong> tab, under the <strong>Composite Patterns for Entity<\/strong> section, add relevant patterns. The various patterns built are similar to the ones used in defining Entity Patterns (<\/span><a href=\"\/docs\/bots\/bot-builder-tool\/train-nlp-optimization\/fundamental-meaning\/fundamental-meaning\/#Navigating_to_the_Patterns_Tab\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-weight: 400;\">refer here for more<\/span><\/a><span style=\"font-weight: 400;\">).<\/span><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15966\" src=\"\/wp-content\/uploads\/sites\/35\/composite_entity_pattern.png\" alt=\"\" width=\"503\" height=\"264\" \/><br \/>\n<span style=\"font-weight: 400;\">For the above composite entity patterns, the following are the sample utterances and the output:<\/span><\/li>\n<\/ol>\n<table>\n<thead>\n<tr>\n<th>Sample Utterance<\/th>\n<th>Corresponding Pattern<\/th>\n<th>Output<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>I want to fly from LA to NY tomorrow, first class with a window seat.<\/td>\n<td>@departurecity @arrivalcity @traveldate @class @seatpreference<\/td>\n<td>\n<pre>\"\r\n\"Flight\": {\r\n\"Departure\": \"LA\",\r\n\"Arrival\": \"NYC\", \"Date\": tomorrow,\r\n\"class\": 1,\"Seatpreference\": Window,\r\n}\r\n}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You can also define the <em>Synonyms <\/em>and <em>Patterns <\/em>as with any other entity.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Limitations\"><span style=\"font-weight: 400;\">Limitations<\/span><\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The Sub-entity with Description cannot be part of a composite entity.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Make sure that the sub-entities are not part of the dialog flow in the task using the composite entity.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">If the sub-entity allows multi-items, the parent composite entity accepts only one value for the sub-entity and not a list.<\/span><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_medium with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Passing_Values\"><span style=\"font-weight: 400;\">Passing Values<\/span><\/span><\/h2>\n<p>You can pass values to composite entities using the entity pre-assignment from source Dialog tasks, <a href=\"\/docs\/bots\/bot-builder-tool\/dialog-task\/working-with-the-dialog-node\/#Define_Instance_Properties\" target=\"_blank\" rel=\"noopener noreferrer\">refer here for more on entity pre-assignment<\/a>.<\/p>\n<p>In terms of composite entities following scenarios can be addressed:<\/p>\n<ol>\n<li><strong>From composite to standard entity<\/strong>: Works as long as the target is of the same entity type as the one used in the source composite.<br \/>\nFor example, <code>context.entities.targetMyCity<\/code> = <code>context.entities.sourceComposite.sourceTravelCity<\/code><\/li>\n<li><strong>From composite to composite<\/strong>: As long as the target is of the same entity type as the one used in the source composite.<br \/>\nFor example, <code>context.entities.sourceComposite.destinationCity<\/code> = <code>context.entities.targetCompsite.myCity<\/code><\/li>\n<li><strong>From standard to composite<\/strong>: As long as the target is of the same entity type as the one used in the source composite.<br \/>\nFor example, <code>context.entities.targetCompsite.myCity<\/code> = <code>context.entities.sourceCity<\/code><\/li>\n<\/ol>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p>Post v8.0.07, you can use the <em>Entity Pre-Assignments<\/em> and <em>Entity Post-Assignments\u00a0<\/em>from the Dialog Node, Instance Properties as shown in the image below (the numbers in the below image correspond to the number in the above use case):<\/p>\n<p><a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20201222065824\/composite_passing_values.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-26153\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20201222065824\/composite_passing_values.png\" alt=\"\" width=\"824\" height=\"654\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20201222065824\/composite_passing_values.png 824w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v10-1\/wp-content\/uploads\/sites\/35\/20201222065824\/composite_passing_values-300x238.png 300w\" sizes=\"auto, (max-width: 824px) 100vw, 824px\" \/><\/a><\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_medium with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"JSON_Object_for_Composite_Entity\"><span style=\"font-weight: 400;\">JSON Object for Composite Entity<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">In v8.0 of the platform, the Composite Entity is enhanced to handle the JSON object as input. This helps in handling the scenarios where the enabled channels send data as a JSON object. For example, MS Teams and Cisco Spark channels. The user input received from these channels is stored as a JSON object in the Context object under the respective composite entity name.<\/span><\/p>\n<p>To enable the composite entity to handle JSON object data, do not add any <em>Patterns<\/em> from the <strong>NLP Properties<\/strong> tab.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_medium with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<div class=\"w-post-elm post_navigation layout_simple inv_false\"><\/div>\n<div class=\"post_navigation-item-arrow\"><\/div>\n<div class=\"post_navigation-item-meta\">Previous<\/div>\n<div class=\"post_navigation-item-title\">Entity Node<\/div>\n<p>&nbsp;<\/p>\n<div class=\"post_navigation-item-meta\"><\/div>\n<div class=\"post_navigation-item-title\"><\/div>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_medium with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction &amp; Use Case\u00a0 Composite Entities help you capture multiple entity values in a user utterance. These multiple entity values are optional and come in any order in the user utterance. Let us consider the below example. A travel agency receives a typical request, which can be of the form: I am interested in traveling&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-18097","post","type-post","status-publish","format-standard","hentry","category-dialog-task"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/18097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/comments?post=18097"}],"version-history":[{"count":22,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/18097\/revisions"}],"predecessor-version":[{"id":60536,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/18097\/revisions\/60536"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/media?parent=18097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/categories?post=18097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/tags?post=18097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}