bravey
Version:
A simple JavaScript NLP-like library to help you creating your own bot.
2,015 lines (565 loc) • 27.6 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: ContextManager</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: ContextManager</h1>
<section>
<header>
<h2>
<span class="ancestors"><a href="Bravey.html">Bravey</a>.</span>ContextManager</h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="ContextManager"><span class="type-signature"></span>new ContextManager<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
The Bravey context manager. Contexts are handled as tags for multiple NLP instances. It store user sessions contexts and query the right NLP when asked.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>extensions.sessionManager</code></td>
<td class="type">
<span class="param-type">SessionManager</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">An instance of a session manager. <a href="Bravey.SessionManager.InMemorySessionManager.html">Bravey.SessionManager.InMemorySessionManager</a> is used when not specified.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="contextmanagers_ContextManager.js.html">contextmanagers/ContextManager.js</a>, <a href="contextmanagers_ContextManager.js.html#line6">line 6</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="addNlp"><span class="type-signature"></span>addNlp<span class="signature">(nlp, contexttags<span class="signature-attributes">opt</span>, method<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Add a NLP instance to the context manager.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>nlp</code></td>
<td class="type">
<span class="param-type">NLP</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">The NLP instance.</td>
</tr>
<tr>
<td class="name"><code>contexttags</code></td>
<td class="type">
<span class="param-type">Array.<String></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
["default"]
</td>
<td class="description last">Related contexts tags.</td>
</tr>
<tr>
<td class="name"><code>method</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last">Method to be used with NLP test. (see Bravey.Nlp.test)</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="contextmanagers_ContextManager.js.html">contextmanagers/ContextManager.js</a>, <a href="contextmanagers_ContextManager.js.html#line20">line 20</a>
</li></ul></dd>
</dl>
<h4 class="name" id="clearSessionIdData"><span class="type-signature"></span>clearSessionIdData<span class="signature">(sessionid)</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
Empty context data for the specified session ID.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sessionid</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The session ID.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="contextmanagers_ContextManager.js.html">contextmanagers/ContextManager.js</a>, <a href="contextmanagers_ContextManager.js.html#line90">line 90</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
True if sessionid is found and context is set.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="getSessionIdData"><span class="type-signature"></span>getSessionIdData<span class="signature">(sessionid)</span><span class="type-signature"> → {Array.<string>}</span></h4>
<div class="description">
Get context data for the specified session ID.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sessionid</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The session ID.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="contextmanagers_ContextManager.js.html">contextmanagers/ContextManager.js</a>, <a href="contextmanagers_ContextManager.js.html#line99">line 99</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
The related data.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.<string></span>
</dd>
</dl>
<h4 class="name" id="removeContext"><span class="type-signature"></span>removeContext<span class="signature">(contexttag)</span><span class="type-signature"></span></h4>
<div class="description">
Remove a context.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>contexttag</code></td>
<td class="type">
<span class="param-type">Array.<String></span>
</td>
<td class="description last">Tag to be deleted</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="contextmanagers_ContextManager.js.html">contextmanagers/ContextManager.js</a>, <a href="contextmanagers_ContextManager.js.html#line61">line 61</a>
</li></ul></dd>
</dl>
<h4 class="name" id="removeNlp"><span class="type-signature"></span>removeNlp<span class="signature">(nlp, contexttags<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Remove a NLP instance to the context manager.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>nlp</code></td>
<td class="type">
<span class="param-type">NLP</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">The NLP instance.</td>
</tr>
<tr>
<td class="name"><code>contexttags</code></td>
<td class="type">
<span class="param-type">Array.<String></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
all
</td>
<td class="description last">Related contexts tags. Will be removed from all contexts if empty.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="contextmanagers_ContextManager.js.html">contextmanagers/ContextManager.js</a>, <a href="contextmanagers_ContextManager.js.html#line41">line 41</a>
</li></ul></dd>
</dl>
<h4 class="name" id="reserveSessionId"><span class="type-signature"></span>reserveSessionId<span class="signature">(id)</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
Reserves a new session ID. It also clear expired sessions.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The session ID to be reserved. Generates a new one if not defined.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="contextmanagers_ContextManager.js.html">contextmanagers/ContextManager.js</a>, <a href="contextmanagers_ContextManager.js.html#line108">line 108</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
The new session ID.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h4 class="name" id="setSessionIdContext"><span class="type-signature"></span>setSessionIdContext<span class="signature">(sessionid, contexttag)</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
Set the context for a given session ID.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sessionid</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">User session ID.</td>
</tr>
<tr>
<td class="name"><code>contexttag</code></td>
<td class="type">
<span class="param-type">Array.<String></span>
</td>
<td class="description last">Tag to be deleted</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="contextmanagers_ContextManager.js.html">contextmanagers/ContextManager.js</a>, <a href="contextmanagers_ContextManager.js.html#line71">line 71</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
True if sessionid is found and context is set.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="setSessionIdData"><span class="type-signature"></span>setSessionIdData<span class="signature">(sessionid, data)</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
Set context data for the specified session ID.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sessionid</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">The session ID.</td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">Key/value pair for data to be set.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="contextmanagers_ContextManager.js.html">contextmanagers/ContextManager.js</a>, <a href="contextmanagers_ContextManager.js.html#line81">line 81</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
True if sessionid is found and context is set.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="testByContext"><span class="type-signature"></span>testByContext<span class="signature">(text, text<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="global.html#ContextManagerResultByContext">ContextManagerResultByContext</a>}</span></h4>
<div class="description">
Check if a given sentence matches an intent and extracts its entities using the specified contexts.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>text</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">The sentence to be processed.</td>
</tr>
<tr>
<td class="name"><code>text</code></td>
<td class="type">
<span class="param-type">Array.<string></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
["default"]
</td>
<td class="description last">The context tags.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="contextmanagers_ContextManager.js.html">contextmanagers/ContextManager.js</a>, <a href="contextmanagers_ContextManager.js.html#line118">line 118</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
When an intent is found.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="global.html#ContextManagerResultByContext">ContextManagerResultByContext</a></span>
</dd>
</dl>
<h4 class="name" id="testBySessionId"><span class="type-signature"></span>testBySessionId<span class="signature">(text, text<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="global.html#ContextManagerResultBySessionId">ContextManagerResultBySessionId</a>|false}</span></h4>
<div class="description">
Check if a given sentence matches an intent and extracts its entities using the specified user session ID. When not specified, a new session ID is generated.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>text</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">The sentence to be processed.</td>
</tr>
<tr>
<td class="name"><code>text</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
<new session id>
</td>
<td class="description last">The user session id.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="contextmanagers_ContextManager.js.html">contextmanagers/ContextManager.js</a>, <a href="contextmanagers_ContextManager.js.html#line143">line 143</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<ul>
<li>
<div class="param-desc">
When an intent is found.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="global.html#ContextManagerResultBySessionId">ContextManagerResultBySessionId</a></span>
</dd>
</dl>
</li>
<li>
<div class="param-desc">
When the sentence doesn't match any intent.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">false</span>
</dd>
</dl>
</li>
</ul>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Bravey.ApiAiAdapter.html">ApiAiAdapter</a></li><li><a href="Bravey.ContextManager.html">ContextManager</a></li><li><a href="Bravey.DocumentClassifier.html">DocumentClassifier</a></li><li><a href="Bravey.EMailEntityRecognizer.html">EMailEntityRecognizer</a></li><li><a href="Bravey.Filter.BasicFilter.html">BasicFilter</a></li><li><a href="Bravey.FreeTextEntityRecognizer.html">FreeTextEntityRecognizer</a></li><li><a href="Bravey.Language.EN.DateEntityRecognizer.html">DateEntityRecognizer</a></li><li><a href="Bravey.Language.EN.FreeTextEntityRecognizer.html">FreeTextEntityRecognizer</a></li><li><a href="Bravey.Language.EN.NumberEntityRecognizer.html">NumberEntityRecognizer</a></li><li><a href="Bravey.Language.EN.Stemmer.html">Stemmer</a></li><li><a href="Bravey.Language.EN.TimeEntityRecognizer.html">TimeEntityRecognizer</a></li><li><a href="Bravey.Language.EN.TimePeriodEntityRecognizer.html">TimePeriodEntityRecognizer</a></li><li><a href="Bravey.Language.IT.DateEntityRecognizer.html">DateEntityRecognizer</a></li><li><a href="Bravey.Language.IT.FreeTextEntityRecognizer.html">FreeTextEntityRecognizer</a></li><li><a href="Bravey.Language.IT.NumberEntityRecognizer.html">NumberEntityRecognizer</a></li><li><a href="Bravey.Language.IT.Stemmer.html">Stemmer</a></li><li><a href="Bravey.Language.IT.TimeEntityRecognizer.html">TimeEntityRecognizer</a></li><li><a href="Bravey.Language.IT.TimePeriodEntityRecognizer.html">TimePeriodEntityRecognizer</a></li><li><a href="Bravey.Language.PT.DateEntityRecognizer.html">DateEntityRecognizer</a></li><li><a href="Bravey.Language.PT.FreeTextEntityRecognizer.html">FreeTextEntityRecognizer</a></li><li><a href="Bravey.Language.PT.NumberEntityRecognizer.html">NumberEntityRecognizer</a></li><li><a href="Bravey.Language.PT.Stemmer.html">Stemmer</a></li><li><a href="Bravey.Language.PT.TimeEntityRecognizer.html">TimeEntityRecognizer</a></li><li><a href="Bravey.Language.PT.TimePeriodEntityRecognizer.html">TimePeriodEntityRecognizer</a></li><li><a href="Bravey.Nlp.Fuzzy.html">Fuzzy</a></li><li><a href="Bravey.Nlp.Sequential.html">Sequential</a></li><li><a href="Bravey.NumberEntityRecognizer.html">NumberEntityRecognizer</a></li><li><a href="Bravey.RegexEntityRecognizer.html">RegexEntityRecognizer</a></li><li><a href="Bravey.SessionManager.InMemorySessionManager.html">InMemorySessionManager</a></li><li><a href="Bravey.StringEntityRecognizer.html">StringEntityRecognizer</a></li><li><a href="Bravey.Text.RegexMap.html">RegexMap</a></li></ul><h3>Namespaces</h3><ul><li><a href="Bravey.html">Bravey</a></li><li><a href="Bravey.Data.html">Data</a></li><li><a href="Bravey.Date.html">Date</a></li><li><a href="Bravey.File.html">File</a></li><li><a href="Bravey.Filter.html">Filter</a></li><li><a href="Bravey.Language.html">Language</a></li><li><a href="Bravey.Language.EN.html">EN</a></li><li><a href="Bravey.Language.IT.html">IT</a></li><li><a href="Bravey.Language.PT.html">PT</a></li><li><a href="Bravey.Nlp.html">Nlp</a></li><li><a href="Bravey.SessionManager.html">SessionManager</a></li><li><a href="Bravey.Text.html">Text</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>