{"id":18097,"date":"2019-01-28T06:44:05","date_gmt":"2019-01-28T06:44:05","guid":{"rendered":"https:\/\/developer.kore.ai\/?post_type=docs&#038;p=15965"},"modified":"2020-12-28T09:04:55","modified_gmt":"2020-12-28T09:04:55","slug":"working-with-composite-entities","status":"publish","type":"post","link":"https:\/\/multisite.korebots.com\/v9-0\/docs\/bots\/bot-builder-tool\/dialog-task\/working-with-composite-entities\/","title":{"rendered":"Composite Entities"},"content":{"rendered":"<section class=\"l-section wpb_row height_auto\"><div class=\"l-section-h i-cf\"><div class=\"g-cols vc_row via_grid cols_1 laptops-cols_inherit tablets-cols_inherit mobiles-cols_1 valign_top type_default stacking_default\"><div class=\"wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"wpb_text_column\"><div class=\"wpb_wrapper\"><p><b>Composite Entities<\/b><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><b><\/b>Let us consider the below example.<\/p>\n<p><b>Car Sales Bot<\/b>: <span style=\"font-weight: 400\">Consider the sales inquiries to car sales. Typical queries can be of the form: <em>I am interested in the <\/em><\/span><em><span style=\"font-weight: 400\">Tesla Model S <\/span><\/em><span style=\"font-weight: 400\"><em>2018 model<\/em> or <em>What would a red Tesla 2010 model cost<\/em> or <em>Tell me about <\/em><\/span><em><span style=\"font-weight: 400\">Tesla Model S<\/span><\/em><span style=\"font-weight: 400\">. As you can see, the bot typically needs to process a combination of details like Make, Model, Year and Color to respond to those queries. <\/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><br \/>\n<b><\/b><\/p>\n<p><b>Composite Entity Patterns<\/b>:<span style=\"font-weight: 400\">\u00a0These patterns help you to establish the relationship between the sub-entities. Sub-entities are included in the composite entity using the @ tag, i.e.,<code>@subentity<\/code> 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=\"\/docs\/bots\/bot-builder-tool\/train-nlp-optimization\/fundamental-meaning\/fundamental-meaning\/#Navigating_to_the_Patterns_Tab\"><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:<\/span><br \/>\n<span style=\"font-weight: 400\"> <code>{{context.entities.&lt;&lt;composite_entity&gt;&gt;.&lt;&lt;sub_entity&gt;&gt; }}<\/code><\/span><br \/>\nYou can access each of the sub-entities using the structure they are defined, as they are accessed when used independently of the composite entity. For example, if the sub-entity is of the type Airport, then one can access the airport name thus: <code>{{context.entities.&lt;&lt;composite_entity&gt;&gt;.&lt;&lt;sub_entity&gt;&gt;.AirportName }}<\/code><\/p>\n<\/div><\/div><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><div class=\"wpb_text_column\"><div class=\"wpb_wrapper\"><h2><span class=\"ez-toc-section\" id=\"Create_a_Composite_Entity\"><\/span><span style=\"font-weight: 400\">Create a Composite Entity<\/span><span class=\"ez-toc-section-end\"><\/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><br \/>\n<\/div><\/div><div class=\"wpb_text_column\"><div class=\"wpb_wrapper\"><\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Create_Sub-Entities\"><\/span><span style=\"font-weight: 400\">Create Sub-Entities<\/span><span class=\"ez-toc-section-end\"><\/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 Car Type from the above example, you must create sub-entities that capture the required details. For example, here is a sample mapping of sub-entities for the car entity:<\/span><\/p>\n<table>\n<thead>\n<tr>\n<th>Related Entity<\/th>\n<th>Entity Type<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Make<\/td>\n<td>List of Items: To capture the name of the car brand from the user utterance. As a developer, you must build this list in the entity.<\/td>\n<\/tr>\n<tr>\n<td>Model<\/td>\n<td>List of Values: To capture the name of the model from the user utterance. As a developer, you must build this list in the entity.<\/td>\n<\/tr>\n<tr>\n<td>Year of Make<\/td>\n<td>Number: To capture the year of manufacturing from the user utterance. Bots recognize numbers automatically.<\/td>\n<\/tr>\n<tr>\n<td>Color<\/td>\n<td>Color: To captures the color from the user utterance. Bots recognize colors automatically.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><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><\/p>\n<\/div><\/div><div class=\"wpb_text_column\"><div class=\"wpb_wrapper\"><h3><span class=\"ez-toc-section\" id=\"Define_a_Composite_Entity\"><\/span><span style=\"font-weight: 400\">Define a Composite Entity<\/span><span class=\"ez-toc-section-end\"><\/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\"><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\/22\/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 buy a 2018 Tesla Model S<\/td>\n<td>@year @make @model<\/td>\n<td>\n<pre>\"Car\": {\r\n\"Year\": 2018,\r\n\"Make\": \"Tesla\",\r\n\"Model\": \"Model S\"\r\n}<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>Can you send me a quote for the 2018 Tesla Model S preferably Red?<\/td>\n<td>@year @make @model preferably @color<\/td>\n<td>\n<pre>\"Car\": {\r\n\"Year\": 2018,\r\n\"Make\": \"Tesla\",\r\n\"Model\": \"Model S\"\r\n\u201cColor\u201d: \u201cRed\u201d\r\n}<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>How are the ratings for Tesla Model S?<\/td>\n<td>@Make @Model<\/td>\n<td>\n<pre>\"Car\": {\r\n\"Make\": \"Tesla\",\r\n\"Model\": \"Model S\"\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<\/div><\/div><div class=\"wpb_text_column\"><div class=\"wpb_wrapper\"><h3><span class=\"ez-toc-section\" id=\"Limitations\"><\/span><span style=\"font-weight: 400\">Limitations<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Sub-entity Types of String, Description, Location, and Date 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<\/div><\/div><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><div class=\"wpb_text_column\"><div class=\"wpb_wrapper\"><h2><span class=\"ez-toc-section\" id=\"Passing_Values\"><\/span><span style=\"font-weight: 400\">Passing Values<\/span><span class=\"ez-toc-section-end\"><\/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\" rel=\"noopener noreferrer\" target=\"_blank\">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 \/>For 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 \/>For 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 \/>For example, <code>context.entities.targetCompsite.myCity<\/code> = <code>context.entities.sourceCity<\/code><\/li>\n<\/ol>\n<\/div><\/div><div class=\"wpb_text_column\"><div class=\"wpb_wrapper\"><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:\/\/s3-us-east-2.amazonaws.com\/kore-wordpress\/developer.kore.ai\/wp-content\/uploads\/sites\/22\/20201222065824\/composite_passing_values.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-26153\" src=\"https:\/\/s3-us-east-2.amazonaws.com\/kore-wordpress\/developer.kore.ai\/wp-content\/uploads\/sites\/22\/20201222065824\/composite_passing_values.png\" alt=\"\" width=\"824\" height=\"654\" \/><\/a><\/p>\n<\/div><\/div><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><div class=\"wpb_text_column\"><div class=\"wpb_wrapper\"><h2><span class=\"ez-toc-section\" id=\"JSON_Object_for_Composite_Entity\"><\/span><span style=\"font-weight: 400\">JSON Object for Composite Entity<\/span><span class=\"ez-toc-section-end\"><\/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<\/div><\/div><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><div class=\"wpb_text_column\"><div class=\"wpb_wrapper\"><h2><span class=\"ez-toc-section\" id=\"How_it_Works\"><\/span><span style=\"font-weight: 400\">How it Works?<\/span><span class=\"ez-toc-section-end\"><\/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><\/div><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><div class=\"wpb_text_column\"><div class=\"wpb_wrapper\"><div class=\"w-post-elm post_navigation layout_simple inv_false\">\n\t<a class=\"post_navigation-item order_first to_prev\" href=\"https:\/\/developer.kore.ai\/docs\/bots\/bot-builder-tool\/dialog-task\/working-with-the-entity-node\/\"><\/p>\n<div class=\"post_navigation-item-arrow\"><\/div>\n<div class=\"post_navigation-item-meta\">Previous<\/div>\n<div class=\"post_navigation-item-title\"><span>Entity Node<\/span><\/div>\n<p><\/a><br \/>\n<a class=\"post_navigation-item order_second to_next\" href=\"#\"><\/p>\n<div class=\"post_navigation-item-meta\"><\/div>\n<div class=\"post_navigation-item-title\"><\/div>\n<p><\/a><\/div>\n<\/div><\/div><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><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"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. Car Sales Bot: Consider the sales inquiries to car sales. Typical queries can be of the form: I am interested in the...","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/multisite.korebots.com\/v9-0\/wp-json\/wp\/v2\/posts\/18097"}],"collection":[{"href":"https:\/\/multisite.korebots.com\/v9-0\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/multisite.korebots.com\/v9-0\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/multisite.korebots.com\/v9-0\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/multisite.korebots.com\/v9-0\/wp-json\/wp\/v2\/comments?post=18097"}],"version-history":[{"count":18,"href":"https:\/\/multisite.korebots.com\/v9-0\/wp-json\/wp\/v2\/posts\/18097\/revisions"}],"predecessor-version":[{"id":25845,"href":"https:\/\/multisite.korebots.com\/v9-0\/wp-json\/wp\/v2\/posts\/18097\/revisions\/25845"}],"wp:attachment":[{"href":"https:\/\/multisite.korebots.com\/v9-0\/wp-json\/wp\/v2\/media?parent=18097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multisite.korebots.com\/v9-0\/wp-json\/wp\/v2\/categories?post=18097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multisite.korebots.com\/v9-0\/wp-json\/wp\/v2\/tags?post=18097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}