{"id":18097,"date":"2019-01-28T06:44:05","date_gmt":"2019-01-28T06:44:05","guid":{"rendered":"https:\/\/developer.kore.ai\/v7-3\/?post_type=docs&#038;p=15965"},"modified":"2021-03-26T08:37:46","modified_gmt":"2021-03-26T08:37:46","slug":"working-with-composite-entities","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v7-3\/docs\/bots\/bot-builder-tool\/dialog-task\/working-with-composite-entities\/","title":{"rendered":"Working with 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 type_default valign_top\"><div class=\"vc_col-sm-12 wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p><b>Composite Entities<\/b><span style=\"font-weight: 400\"> help you capture multiple entity values in a user utterance. These multiple entity values can be optional and can come in any order in the user utterance.<\/span><br \/>\n<b><\/b><br \/>\n<b>Example: Car Sales Bot: <\/b><span style=\"font-weight: 400\">Consider the sales inquiries to car sales. Typical queries can be of the form: \u2018<em>I am interested in <\/em><\/span><em><span style=\"font-weight: 400\">Tesla Model S <\/span><\/em><span style=\"font-weight: 400\"><em>2018 model<\/em>\u2019 or \u2018<em>What would a red Tesla 2010 model cost<\/em>\u2019 or \u2018<em>Tell me about <\/em><\/span><em><span style=\"font-weight: 400\">Tesla Model S<\/span><\/em><span style=\"font-weight: 400\">\u2019. 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 can 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\"> <span style=\"text-decoration: underline\">have to be used<\/span> to establish the relationship between the sub-entities. Subentities are included in the composite entity using the @ tag, i.e.,<code>@subentity<\/code> in the composite entity pattern. These sub-entities need to be pre-defined and should not be part of the current dialog flow. The sub-entities can come from other Dialog Tasks, too. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Various patterns like AND, OR etc. can be built, similar to the ones used in defining Entity Patterns (<\/span><a href=\"\/v7-3\/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 subentities can be referenced as properties of that object, i.e. to access a subentity 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 \/>\nEach of the sub-entities can be accessed using the structure they were defined, as they will be 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\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=\"Creating_a_Composite_Entity\"><span style=\"font-weight: 400\">Creating a Composite Entity<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400\">Building a composite entity involves the following steps &#8211; creating sub-entities and establishing a relationship between these sub-entities.<\/span><\/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<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 first need to build the individual entities in the Dialog task. To capture the Car Type from the above example, you first need to create the sub-entities that can capture the required details. For example, here\u2019s 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 should 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 should 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 should not be used 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\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<h3><span class=\"ez-toc-section\" id=\"Define_Composite_Entity\"><span style=\"font-weight: 400\">Define 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 do so, open the Properties Panel, and under the Composite Patterns section, add relevant patterns. The various patterns that can be built are similar to the ones used in defining Entity Patterns (<\/span><a href=\"\/v7-3\/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\/15\/composite_entity_pattern.png\" alt=\"\" width=\"503\" height=\"264\" \/><br \/>\n<span style=\"font-weight: 400\">For the above composite entity patterns, following are the sample utterances and the output:<\/span><\/p>\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 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 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 Synonyms and Patterns as with any other Entity.<\/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<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\">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 will accept only one value for the sub-entity and not a list.<\/span><\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"How_it_works\"><span style=\"font-weight: 400\">How it works<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400\">When a composite entity is reached in the dialog flow:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">all the possible subentities 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 subentities 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 subentity instances captured. <\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">What that means is that the composite entity pattern is not used to identify the subentities but to match the entire pattern.<\/span><\/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><\/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 can be optional and can come in any order in the user utterance. Example: Car Sales Bot: Consider the sales inquiries to car sales. Typical queries can be of the form: \u2018I am interested in Tesla Model S 2018...","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\/v7-3\/wp-json\/wp\/v2\/posts\/18097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/comments?post=18097"}],"version-history":[{"count":4,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/posts\/18097\/revisions"}],"predecessor-version":[{"id":22860,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/posts\/18097\/revisions\/22860"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/media?parent=18097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/categories?post=18097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/tags?post=18097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}