{
    "componentChunkName": "component---src-templates-doc-page-js",
    "path": "/docs/en/script_development/switch_states/",
    "result": {"data":{"site":{"siteMetadata":{"title":"Gatsby-doc-engine"}},"markdownRemark":{"id":"788b2dc0-5738-5620-8a9b-7755817c9d94","excerpt":"Switching states A chat bot script is defined in a text file with a tree structure. This means some elements are nested in other ones. These elements are states…","html":"<h1>Switching states</h1>\n<hr>\n<p>A chat bot script is defined in a text file with a tree structure. This means some elements are nested in other ones. These elements are states of the system it can switch to in the course of a conversation. <a href=\"/1.10.3/docs/en/JAICP_DSL/tags/declarative_tags/state\">They are called system states</a>. Generic states include more specific states.</p>\n</br>\n<h4>Switching to a state</h4>\n<p>A state is switched in the following cases:</p>\n<ul>\n<li>The client’s request falls under one of the global tags: <a href=\"/1.10.3/docs/en/JAICP_DSL/tags/declarative_tags/q!\"><code class=\"language-text\">q!</code></a>, <a href=\"/1.10.3/docs/en/classificator/e!\"><code class=\"language-text\">e!</code></a>, <a href=\"/1.10.3/docs/en/classificator/eg!\"><code class=\"language-text\">eg!</code></a> or <a href=\"/1.10.3/docs/en/NLU_core/intent!\"><code class=\"language-text\">intent!</code></a>.</li>\n</ul>\n<p class='warn'>Activation rules for patterns, intents and groups of examples in a script <a href=/1.10.3/docs/en/NLU_core/intent_detection  >are processed for the following objects in descending priority</a>: <code class=\"language-text\">q!</code>, <code class=\"language-text\">eg!</code>, <code class=\"language-text\">intent!</code>.</p>\n<p>The conversation can switch to a global tag state from any other state. A local tag is only active in the context of the conversation; you can switch to this state from one of the nearest parent or child states.</p>\n<ul>\n<li>The client’s request falls under the <a href=\"/1.10.3/docs/en/JAICP_DSL/tags/declarative_tags/q\"><code class=\"language-text\">q</code></a> tag pattern.</li>\n<li>From the parent state, if the client’s request falls under a nested state.</li>\n<li>From any state, if the <a href=\"/1.10.3/docs/en/script_development/context#fromstate\"><code class=\"language-text\">fromState</code></a> state is specified for the <code class=\"language-text\">q</code> tag. This flag defines the state from which a switch based on this pattern is possible.</li>\n<li>When a <a href=\"/1.10.3/docs/en/JAICP_DSL/tags/reaction_tags/go!\"><code class=\"language-text\">go!</code></a> or <a href=\"/1.10.3/docs/en/JAICP_DSL/tags/reaction_tags/go\"><code class=\"language-text\">go</code></a> tag is activated.</li>\n</ul>\n</br>\n<h4>Processing activation rules</h4>\n<p>When the system is in a state, rules associated with that state and all its parents are activated. Activation rules associated with that state have the highest priority.</p>\n<p>Therefore, identical activation rules can be declared in different states, but they are processed depending on the current state of the system.</p>\n<p>Consider the following script:</p>\n<div class=\"gatsby-highlight\" data-language=\"sc\"><pre class=\"language-sc\"><code class=\"language-sc\"><span class=\"token keyword\">patterns:</span>\n    $Yes = (yes|of course)\n    $No = (no|not|no way)\n\n<span class=\"token keyword\">theme:</span> /\n    <span class=\"token keyword\">state:</span> Start\n        <span class=\"token storageType\">q!:</span> $regexp&lt;/start>\n        <span class=\"token variableParameter\">go!:</span> ../morning exercise\n\n    <span class=\"token keyword\">state:</span> morning exercise\n        <span class=\"token variableParameter\">a:</span> Do you do morning exercise?\n\n        <span class=\"token keyword\">state:</span> every day\n            <span class=\"token storageType\">q:</span> * $Yes *\n            <span class=\"token variableParameter\">a:</span> Do you do morning exercise every day?\n\n            <span class=\"token keyword\">state:</span>\n                <span class=\"token storageType\">q:</span> * $Yes *\n                <span class=\"token variableParameter\">a:</span> Good!\n\n            <span class=\"token keyword\">state:</span>\n                <span class=\"token storageType\">q:</span> * $No *\n                <span class=\"token variableParameter\">a:</span> Morning exercise has to become your habit!\n\n        <span class=\"token keyword\">state:</span>\n            <span class=\"token storageType\">q:</span> * $No *\n            <span class=\"token variableParameter\">a:</span> Morning exercise helps your body and brain wake up, work on yourself!</code></pre></div>\n</br>\n<p>This script shows how a client’s <code class=\"language-text\">yes/no</code> answers are processed depending on the active state.</p>\n<p>Let us have a look at how this script is processed:</p>\n<ol>\n<li>The script is started, <code class=\"language-text\">go!</code> redirect the client to the <code class=\"language-text\">morning exercise</code> state.</li>\n<li>The bot asks <code class=\"language-text\">Do you do morning exercise?</code> from the <code class=\"language-text\">morning exercise</code> state.</li>\n<li>The system will then remain the current state where the patterns are active: <code class=\"language-text\">q: * $Yes *</code>, <code class=\"language-text\">q: * $No *</code>.</li>\n<li>The client answers <code class=\"language-text\">yes</code> and the system switches to the <code class=\"language-text\">morning exercise/every day</code> state. The bot then asks <code class=\"language-text\">Do you do morning exercise every day?</code>, and the system activates the next set of patterns.</li>\n<li>The system will interpret the next answer of the client in the <code class=\"language-text\">morning exercise/every day</code> context. Responses activate nested state patterns as they have a higher priority.</li>\n</ol>","frontmatter":{"title":"","description":null},"headings":[{"value":"Switching states"}]}},"pageContext":{"slug":"/docs/en/script_development/switch_states/","previous":{"fields":{"slug":"/docs/en/script_development/context/"},"frontmatter":{"title":"","description":null}},"next":{"fields":null,"frontmatter":{"title":"","description":null}}}},
    "staticQueryHashes": ["1209419333"]}