{
    "componentChunkName": "component---src-templates-doc-page-js",
    "path": "/docs/en/NLU_core/entities/",
    "result": {"data":{"site":{"siteMetadata":{"title":"Gatsby-doc-engine"}},"markdownRemark":{"id":"9b2e6f7d-299e-5cf6-8ec8-3b08a9ec42dd","excerpt":"System and custom entities An entity is a unit of the NLU core of CAILA. An entity is a sequence of words linked by an intent or rule. For example: names, date…","html":"<h1>System and custom entities</h1>\n<hr>\n<p>An entity is a unit of the NLU core of CAILA. An entity is a sequence of words linked by an intent or rule. For example: names, date and time, location, etc.</p>\n<p>CAILA offers the following to the developer:</p>\n<ul>\n<li><em>System entities</em> — built-in entities that the developer can activate in the entity editor.</li>\n<li><em>My entities</em> — entities that the developer enters and constructs in the entity editor.</li>\n</ul>\n<p class='warn'><a href=/1.10.3/docs/en/platform_ux/nlu_core_caila/entities  >More about the entity editor</a></p>\n</br>\n<h3>Using entities</h3>\n<h4>Directly</h4>\n<p>All entities found in a phrase will be available in the script via the variable <code class=\"language-text\">$jsapi.context().entities</code> or <code class=\"language-text\">$entities</code>.</p>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span>\n        <span class=\"token storageType\">q!:</span> Information about product *\n        <span class=\"token variableParameter\">a:</span> Information about product: <span class=\"token constantCharacter\">{{ $entities[0].value }}</span></code></pre></div>\n</br>\n<h4>In intents</h4>\n<p>Entities can be used in <a href=\"/1.10.3/docs/en/NLU_core/intent\">intents</a>.</p>\n<p class='warn'>More details about <a href=/1.10.3/docs/en/platform_ux/nlu_core_caila/intents  >filling in slots in intents</a> and <a href=/1.10.3/docs/en/NLU_core/slot_filling  >the Slot filling process</a></p>\n<p>When the intent is activated, the data of the respective slot will be written to the variable <code class=\"language-text\">$parseTree._&lt;slot name></code>.</p>\n<p>The initial text for which a match has been found will be written to this variable; alternatively, the <a href=\"/1.10.3/docs/en/NLU_core/data\"><code class=\"language-text\">DATA</code></a> specified for this entity in the entity editor will be written to this variable.</p>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span>\n        <span class=\"token storageType\">intent:</span> /bye\n        <span class=\"token variableParameter\">a:</span> Action: <span class=\"token constantCharacter\">{{ $parseTree._Action }}</span>, Product: <span class=\"token constantCharacter\">{{ $parseTree._Product }}</span>\n\n    <span class=\"token keyword\">state:</span>\n        <span class=\"token storageType\">intent:</span> /sell\n        <span class=\"token variableParameter\">a:</span> Action: <span class=\"token constantCharacter\">{{ $parseTree._Action }}</span>, Product: <span class=\"token constantCharacter\">{{ $parseTree._Product }}</span></code></pre></div>\n</br>\n<h4>In patterns</h4>\n<p>You can use entities in <a href=\"/1.10.3/docs/en/Patterns/about_patterns\">patterns</a> by referencing them as <code class=\"language-text\">@&lt;entity name></code> or <code class=\"language-text\">@&lt;entity name>::&lt;slot name></code>.</p>\n<p>For an entity specified in a pattern, a slot is created automatically and the entity is included in the <a href=\"/1.10.3/docs/en/JS_API/variables/parseTree\"><code class=\"language-text\">$parseTree</code></a>.</p>\n<p>The value of the entity will be available in the script as <code class=\"language-text\">$parseTree._&lt;slot name></code>.</p>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span>\n        <span class=\"token storageType\">q!:</span> * @Product::p1 *\n        <span class=\"token variableParameter\">a:</span> Information about product: <span class=\"token constantCharacter\">{{ $parseTree._p1 }}</span></code></pre></div>\n</br>\n<p>You can also use <a href=\"/1.10.3/docs/en/Patterns/converters\">converters</a> in entities. First, you need to define an entity through a named pattern using the <a href=\"/1.10.3/docs/en/JAICP_DSL/tags/declarative_tags/patterns\"><code class=\"language-text\">patterns</code></a> tag, and then declare a converter in it. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\"><span class=\"token keyword\">patterns:</span>\n    $four = @four || converter = function() {return 4}</code></pre></div>\n<p>In this example we created <code class=\"language-text\">@four</code> entity, in which we declared <code class=\"language-text\">converter</code>. The converter function returns <code class=\"language-text\">4</code>.</p>\n</br>\n<h4>In the examples of STS classifier phrases</h4>\n<p>You can use entities in the phrase examples of <a href=\"/1.10.3/docs/en/classificator/work_with_classificator\">STS classifier</a> by referencing them as <code class=\"language-text\">@&lt;entity name></code> or <code class=\"language-text\">@&lt;entity name>::&lt;slot name></code>.</p>\n<p>For the entity specified in the example, a slot is automatically created and the entity is included in the <a href=\"/1.10.3/docs/en/JS_API/variables/parseTree\"><code class=\"language-text\">$parseTree</code></a>.</p>\n<p>The value of the entity will be available in the script as <code class=\"language-text\">$parseTree._&lt;slot name></code>.</p>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\">    <span class=\"token keyword\">state:</span>\n        <span class=\"token storageType\">e!:</span> @Pizza::p2\n        <span class=\"token variableParameter\">a:</span> Information about pizza: <span class=\"token constantCharacter\">{{ $parseTree._p2 }}</span></code></pre></div>\n</br>\n<h4>In entities</h4>\n<p>In JAICP entities can refer to other entities.</p>\n<p>Let's have a look at entities behavior when:</p>\n<ul>\n<li><a href=\"#Filling-a-Value-field\">filling a <em>Value</em> field</a>;</li>\n<li><a href=\"#Filling-a-Data-field\">filling a <em>Data</em> field</a>.</li>\n</ul>\n<h5>Filling a <em>Value</em> field</h5>\n<p>Let's have a look at how the client's address fills in the entities. The address consists of two parts: street and house number.</p>\n<p>Go to the <em>CAILA > Entities > My entities</em> tab on the control panel. Create the following entities:</p>\n<ul>\n<li><code class=\"language-text\">street_name</code> with patterns:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Main\nWest</code></pre></div>\n<ul>\n<li><code class=\"language-text\">street</code> with a pattern:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">@street_name street</code></pre></div>\n<p>Now let's create a <code class=\"language-text\">address</code> entity. It refers to the <code class=\"language-text\">street</code> entity and the <a href=\"/1.10.3/docs/en/NLU_core/duckling\"><code class=\"language-text\">@duckling.number</code></a> system entity:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">@street @duckling.number</code></pre></div>\n<p>Now let's say the client enters the message <em>Main Street</em>. The <em>Value</em> field is filled in the following way:</p>\n<ul>\n<li><code class=\"language-text\">Main</code> in the <code class=\"language-text\">street_name</code> entity;</li>\n<li><code class=\"language-text\">Main street</code> in the <code class=\"language-text\">street</code> entity.</li>\n</ul>\n<p>If the client enters the message <em>Main Street 15</em>, then <em>Value</em> fills in as follows:</p>\n<ul>\n<li><code class=\"language-text\">Main</code> in the <code class=\"language-text\">street_name</code> entity;</li>\n<li><code class=\"language-text\">Main street</code> in the <code class=\"language-text\">street</code> entity;</li>\n<li><code class=\"language-text\">Main Street 15</code> in the <code class=\"language-text\">address</code> entity.</li>\n</ul>\n</br>\n<h5>Filling a <em>Data</em> field</h5>\n<p>Let's say we have our own online store that sells groceries. We will use the entities to specify from the client's request what kind of fruits and vegetables they want to buy.</p>\n<p>Go to the <em>CAILA > Entities > My entities</em> tab on the control panel. Create the following entities:</p>\n<ul>\n<li><code class=\"language-text\">fruit</code> with patterns:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">apple\nbanana\nlime</code></pre></div>\n<ul>\n<li><code class=\"language-text\">vegetable</code> with patterns:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">potato\ntomato\ncucumber</code></pre></div>\n</br>\n<p>In addition, specify values <code class=\"language-text\">name</code> and <code class=\"language-text\">type</code> in the <a href=\"/1.10.3/docs/en/NLU_core/data\"><em>DATA</em></a> field for each pattern that will correspond to the name and type of the product. In the <em>DATA</em> field, you can add any information in <code class=\"language-text\">JSON</code> format that may be needed in the script.</p>\n<p>For example, for the pattern <code class=\"language-text\">banana</code> specify:</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token punctuation\">{</span>\n    <span class=\"token property\">\"name\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token property\">\"type\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"fruit\"</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Do the same for each pattern of the <code class=\"language-text\">vegetable</code> entity. For instance:</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token punctuation\">{</span>\n    <span class=\"token property\">\"name\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"potato\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token property\">\"type\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"vegetable\"</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now, let's combine these entities into the <code class=\"language-text\">grocery</code> entity. Create an entity <code class=\"language-text\">grocery</code> and specify the patterns <code class=\"language-text\">@vegetable</code> and <code class=\"language-text\">@fruit</code> in the <em>Dictionary</em> field.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 1919px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 44.79166666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAABYlAAAWJQFJUiTwAAABuElEQVQoz4WRTWsTURSG5ycIgqBGi1qSSWr6kSa2ThC6lNKNC0GEloC7igiuKkoTpGK7UHDjWty4EQT/h1vdCDGZ1KTVmclkvu5kknnk3mLpIuqBh/eFl3s451zt85dviHhInKI0BdI0ZTwe/xWZx3GMEIIwDIniIQOR4IUC7db6PR49f8nm0x0eNnbZ3Krz/sNHojAkCAL1YCJRpIikhiFCRDi2jaaXDaaLJS5mZ7hSmOXM2fM8aTToOod0e10sy8ayrP/iOA7NZhOtuHaXwv09MrVtLtTqnLrzmPq7TwSei2XbBL6P73nHeBMYDAZqm3arhZa/cZOp1XWmVje4vFbj9MptGm/ekoiIft+lH0S44RHSR0Ko+51E3nI0GmGaJpq+cI3c1Tn04jwzcyUyl6bZebFHkiT0ege4cgLfx/MDpX4QqGlO4vk+fT+k2ztA0xevky0dka9UOZctsvvqNbKGcaxUftC/agxYCXiui5YrLZFdWCJXWiZfNsjos2xtP+Pw5y++t03Mzj4t06RtdpSfhMxanR98be2jzRsrqtGfplL1xWUKZUMhs0KleuwnITO9UsXYeMBv8Qo00J0SutQAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Entity grocery\"\n        title=\"Entity grocery\"\n        src=\"/1.10.3/static/503b888742657cef7c8c6aa8027c25b9/7ebf9/Screenshot_3.png\"\n        srcset=\"/1.10.3/static/503b888742657cef7c8c6aa8027c25b9/e85cb/Screenshot_3.png 480w,\n/1.10.3/static/503b888742657cef7c8c6aa8027c25b9/d9199/Screenshot_3.png 960w,\n/1.10.3/static/503b888742657cef7c8c6aa8027c25b9/7ebf9/Screenshot_3.png 1919w\"\n        sizes=\"(max-width: 1919px) 100vw, 1919px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n    </span></p>\n</br>\n<p>Let's look at the script. The user sends a message containing information about the product he wants. The bot's reply will consist of two messages: the name and type of this product.</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\"><span class=\"token keyword\">state:</span> Start\n    <span class=\"token storageType\">q!:</span> $regex&lt;/start>\n    <span class=\"token variableParameter\">a:</span> Hello! Our store offers a wide range of vegetables and fruit. What would you like to order?\n\n    <span class=\"token keyword\">state:</span> Grocery\n        <span class=\"token storageType\">q!:</span> * @grocery *\n        <span class=\"token variableParameter\">script:</span>\n            $reactions.answer(\"The name of the product: <span class=\"token constantCharacter\">{{ $parseTree._grocery.name }}</span>\");\n            $reactions.answer(\"The type of the product: <span class=\"token constantCharacter\">{{ $parseTree._grocery.type }}</span>\");</code></pre></div>\n<p>For example, the client writes the message <em>Potato</em>. The <em>DATA</em> field of the <code class=\"language-text\">grocery</code> entity will be filled with the information specified in the <em>DATA</em> field of the <code class=\"language-text\">vegetable</code> entity. Because the entity <code class=\"language-text\">grocery</code> contains the entity <code class=\"language-text\">vegetable</code> the message will be recognized by both these entities. In a result, the bot will send the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The name of the product: potato\nThe type of the product: vegetable</code></pre></div>\n</br>\n<h3>Filling the $entities array</h3>\n<p>Let us consider a situation where we have multiple matches for an entity search query.</p>\n<p>Create a <code class=\"language-text\">@City</code> <a href=\"/1.10.3/docs/en/platform_ux/nlu_core_caila/entities\">custom entity</a>. Add the two values of <code class=\"language-text\">South Carolina</code> and <code class=\"language-text\">North Carolina</code> to the entity’s reference list. If a client requests <code class=\"language-text\">Carolina</code>, the bot must prompt to specify which city the client means.</p>\n<p class='warn'>All the values of the entity must be in the <code class=\"language-text\">$entities</code> array.</p>\n<p>Use the <a href=\"/1.10.3/docs/en/NLU_core/CAILA_direct_API/CAILA_direct_API\">CAILA API method</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PUT /cailapub/api/caila/p/{accessToken}/entities/{entityId}</code></pre></div>\n</br>\n<p>Add a parameter for the <code class=\"language-text\">@City</code> entity:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  \"fuzzySearch\": true    // can be used to find multiple values and add them to the array.\n}</code></pre></div>\n<p>The <code class=\"language-text\">$context.entities</code> array will now contain the list with the <code class=\"language-text\">South Carolina</code> and <code class=\"language-text\">North Carolina</code> values, and the bot may prompt the client to specify the city.</p>","frontmatter":{"title":"","description":null},"headings":[{"value":"System and custom entities"}]}},"pageContext":{"slug":"/docs/en/NLU_core/entities/","previous":{"fields":{"slug":"/docs/en/NLU_core/intent!/"},"frontmatter":{"title":"","description":null}},"next":{"fields":{"slug":"/docs/en/NLU_core/duckling/"},"frontmatter":{"title":"","description":null}}}},
    "staticQueryHashes": ["1209419333"]}