{
    "componentChunkName": "component---src-templates-doc-page-js",
    "path": "/docs/en/NLU_core/rule_activation/",
    "result": {"data":{"site":{"siteMetadata":{"title":"Gatsby-doc-engine"}},"markdownRemark":{"id":"81a31ed2-2fba-510e-8e8e-f93183e288ce","excerpt":"Configuring activation rules The chatbot developer can define the state triggering mechanism when intents, patterns and example groups are used together. The…","html":"<h1>Configuring activation rules</h1>\n<hr>\n<p>The chatbot developer can define the <a href=\"/1.10.3/docs/en/NLU_core/intent_detection\">state triggering mechanism when intents, patterns and example groups are used together</a>.</p>\n<p>The context <code class=\"language-text\">ctx</code> that contains the <code class=\"language-text\">nluResults field</code> is passed to the handler function as a parameter. The object <code class=\"language-text\">nluResults</code> contains the following fields:</p>\n<ul>\n<li><code class=\"language-text\">patterns</code> — an array of results from the pattern matcher;</li>\n<li><code class=\"language-text\">examples</code> — an array of results from the examples;</li>\n<li><code class=\"language-text\">intents</code> — an array of results from the intents;</li>\n<li><code class=\"language-text\">selected</code> — the result selected by default.</li>\n</ul>\n<p class='tip'>To change the result source, change the value of the field <code class=\"language-text\">selected</code>.</p>\n</br>\n<h4>An example</h4>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\"><span class=\"token keyword\">theme:</span>/\n\n    <span class=\"token keyword\">init:</span>                                                       //declare the handler\n      \n        bind(\"selectNLUResult\", function(ctx) {                 //define the handler for the `selectNLUResult` phase\n            log(ctx.nluResults);                                <span class=\"token comment\">// output the results to the log</span>\n            \n        if (ctx.nluResults.intents.length > 0){\n          ctx.nluResults.selected = ctx.nluResults.intents[0];  <span class=\"token comment\">// use the result from the intents</span>\n          return;\n        }\n        \n        if (ctx.nluResults.patterns.length > 0){\n          ctx.nluResults.selected = ctx.nluResults.patterns[0];  <span class=\"token comment\">// if there is no result from the intents, use patterns</span>\n          return;\n        }\n        \n        if (ctx.nluResults.examples.length > 0){\n          ctx.nluResults.selected = ctx.nluResults.examples[0];  <span class=\"token comment\">// if there is no result either from the intents or from the patterns, use the examples</span>\n        }\n\n        })</code></pre></div>\n<ol>\n<li>We declare the handler in the <a href=\"/1.10.3/docs/en/JAICP_DSL/tags/declarative_tags/init\"><code class=\"language-text\">init</code></a> section. You can also specify the handler in a separate JS file and connect it to the script using <a href=\"/1.10.3/docs/en/JAICP_DSL/tags/declarative_tags/require\"><code class=\"language-text\">require</code></a>.</li>\n<li>Define the handler for the <code class=\"language-text\">selectNLUResult</code> phase.</li>\n<li>Output the results to the log: <code class=\"language-text\">log(ctx.nluResults)</code>.</li>\n<li>Then we define the order in which the results are used:\n<ul>\n<li>use the result from the intents: <code class=\"language-text\">ctx.nluResults.selected = ctx.nluResults.intents\\[0]</code>;</li>\n<li>use the result from the pattern matcher: <code class=\"language-text\">ctx.nluResults.selected = ctx.nluResults.patterns\\[0]</code>;</li>\n<li>use the result from the examples: <code class=\"language-text\">ctx.nluResults.selected = ctx.nluResults.examples\\[0]</code>.</li>\n</ul>\n</li>\n</ol>","frontmatter":{"title":"","description":null},"headings":[{"value":"Configuring activation rules"}]}},"pageContext":{"slug":"/docs/en/NLU_core/rule_activation/","previous":{"fields":{"slug":"/docs/en/NLU_core/slot_filling/"},"frontmatter":{"title":"","description":null}},"next":{"fields":{"slug":"/docs/en/NLU_core/project_migration/"},"frontmatter":{"title":"","description":null}}}},
    "staticQueryHashes": ["1209419333"]}