node-nlp
Version:
Library for NLU (Natural Language Understanding) done in Node.js
1,627 lines (423 loc) • 20.2 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: NlpClassifier</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: NlpClassifier</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>NlpClassifier<span class="signature">(settings)</span><span class="type-signature"></span></h2>
<div class="class-description">Class for the NLP Classifier.
In the settings you can specify:
- classifier (optional): The Machine Learning Classifier Class. If not
provided, then a default Logistic Regression Classifier is used.
- stemmer (optional): The language stemmer (also tokenize). If not
provided, you can provide the language and the default stemmer
for this language will be used.
- language (optional): If you don't provide a stemmer, then you can
provide a language so a default stemmer for this language will
be used.</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="NlpClassifier"><span class="type-signature"></span>new NlpClassifier<span class="signature">(settings)</span><span class="type-signature"></span></h4>
<div class="description">
Constructor of the class.
</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>settings</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">Settings for this instance.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="nlp_nlp-classifier.js.html">nlp/nlp-classifier.js</a>, <a href="nlp_nlp-classifier.js.html#line40">line 40</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="add"><span class="type-signature"></span>add<span class="signature">(srcUtterance, srcIntent)</span><span class="type-signature"></span></h4>
<div class="description">
Adds a new utterance to an intent.
</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>srcUtterance</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Utterance to be added.</td>
</tr>
<tr>
<td class="name"><code>srcIntent</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Intent for adding the utterance.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="nlp_nlp-classifier.js.html">nlp/nlp-classifier.js</a>, <a href="nlp_nlp-classifier.js.html#line119">line 119</a>
</li></ul></dd>
</dl>
<h4 class="name" id="existsUtterance"><span class="type-signature"></span>existsUtterance<span class="signature">(utterance, intent)</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
Indicates if an utterance already exists, at the given intent or globally.
</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>utterance</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Utterance to be checked.</td>
</tr>
<tr>
<td class="name"><code>intent</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Intent to check, undefined to search globally.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="nlp_nlp-classifier.js.html">nlp/nlp-classifier.js</a>, <a href="nlp_nlp-classifier.js.html#line110">line 110</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
True if the intent exists, false otherwise.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="getBestClassification"><span class="type-signature"></span>getBestClassification<span class="signature">(utterance)</span><span class="type-signature"> → {Object}</span></h4>
<div class="description">
Given an utterance, get the label and score of the best classification.
</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>utterance</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Utterance to be classified.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="nlp_nlp-classifier.js.html">nlp/nlp-classifier.js</a>, <a href="nlp_nlp-classifier.js.html#line293">line 293</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Best classification of the observation.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="getClassifications"><span class="type-signature"></span>getClassifications<span class="signature">(utterance)</span><span class="type-signature"> → {Array.<Object>}</span></h4>
<div class="description">
Get all the labels and score for each label from this utterance.
</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>utterance</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Utterance to be classified.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="nlp_nlp-classifier.js.html">nlp/nlp-classifier.js</a>, <a href="nlp_nlp-classifier.js.html#line260">line 260</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Sorted array of classifications, with label and score.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.<Object></span>
</dd>
</dl>
<h4 class="name" id="posUtterance"><span class="type-signature"></span>posUtterance<span class="signature">(srcUtterance, intent)</span><span class="type-signature"> → {Number}</span></h4>
<div class="description">
Gets the position of a utterance for an intent.
</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>srcUtterance</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">Utterance to be found.</td>
</tr>
<tr>
<td class="name"><code>intent</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">Intent of the utterance.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="nlp_nlp-classifier.js.html">nlp/nlp-classifier.js</a>, <a href="nlp_nlp-classifier.js.html#line89">line 89</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Position of the utterance, -1 if not found.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Number</span>
</dd>
</dl>
<h4 class="name" id="remove"><span class="type-signature"></span>remove<span class="signature">(srcUtterance, srcIntent)</span><span class="type-signature"></span></h4>
<div class="description">
Remove an utterance from the classifier.
</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>srcUtterance</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Utterance to be removed.</td>
</tr>
<tr>
<td class="name"><code>srcIntent</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Intent of the utterance, undefined to search all</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="nlp_nlp-classifier.js.html">nlp/nlp-classifier.js</a>, <a href="nlp_nlp-classifier.js.html#line143">line 143</a>
</li></ul></dd>
</dl>
<h4 class="name" id="textToFeatures"><span class="type-signature"></span>textToFeatures<span class="signature">(srcUtterance)</span><span class="type-signature"> → {Array.<Number>}</span></h4>
<div class="description">
Given an utterance, tokenize and steam the utterance and convert it
to a vector of binary values, where each position is a feature (a word
stemmed) and the value means if the utterance has this feature.
The input utterance can be an string or an array of tokens.
</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>srcUtterance</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Utterance to be converted to features vector.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="nlp_nlp-classifier.js.html">nlp/nlp-classifier.js</a>, <a href="nlp_nlp-classifier.js.html#line172">line 172</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Features vector of the utterance.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.<Number></span>
</dd>
</dl>
<h4 class="name" id="tokenizeAndStem"><span class="type-signature"></span>tokenizeAndStem<span class="signature">(utterance)</span><span class="type-signature"> → {Array.<String>}</span></h4>
<div class="description">
Generate the vector of features.
</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>utterance</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Input utterance.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="nlp_nlp-classifier.js.html">nlp/nlp-classifier.js</a>, <a href="nlp_nlp-classifier.js.html#line74">line 74</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Vector of features.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.<String></span>
</dd>
</dl>
<h4 class="name" id="train"><span class="type-signature">(async) </span>train<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Train the classifier with the existing utterances and intents.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="nlp_nlp-classifier.js.html">nlp/nlp-classifier.js</a>, <a href="nlp_nlp-classifier.js.html#line206">line 206</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BinaryNeuralNetworkClassifier.html">BinaryNeuralNetworkClassifier</a></li><li><a href="Classifier.html">Classifier</a></li><li><a href="ConversationContext.html">ConversationContext</a></li><li><a href="DutchStemmer.html">DutchStemmer</a></li><li><a href="EnglishStemmer.html">EnglishStemmer</a></li><li><a href="EnumNamedEntity.html">EnumNamedEntity</a></li><li><a href="Evaluator.html">Evaluator</a></li><li><a href="HungarianStemmer.html">HungarianStemmer</a></li><li><a href="ItalianStemmer.html">ItalianStemmer</a></li><li><a href="Language.html">Language</a></li><li><a href="LogisticRegressionClassifier.html">LogisticRegressionClassifier</a></li><li><a href="Matrix.html">Matrix</a></li><li><a href="MemoryConversationContext.html">MemoryConversationContext</a></li><li><a href="NamedEntity.html">NamedEntity</a></li><li><a href="NerManager.html">NerManager</a></li><li><a href="NlgManager.html">NlgManager</a></li><li><a href="NlpClassifier.html">NlpClassifier</a></li><li><a href="NlpManager.html">NlpManager</a></li><li><a href="NorwegianStemmer.html">NorwegianStemmer</a></li><li><a href="PortugueseStemmer.html">PortugueseStemmer</a></li><li><a href="Recognizer.html">Recognizer</a></li><li><a href="RegexNamedEntity.html">RegexNamedEntity</a></li><li><a href="RomanianStemmer.html">RomanianStemmer</a></li><li><a href="RussianStemmer.html">RussianStemmer</a></li><li><a href="SentimentAnalyzer.html">SentimentAnalyzer</a></li><li><a href="SentimentManager.html">SentimentManager</a></li><li><a href="SimilarSearch.html">SimilarSearch</a></li><li><a href="SlotManager.html">SlotManager</a></li><li><a href="StemmerJa.html">StemmerJa</a></li><li><a href="SwedishStemmer.html">SwedishStemmer</a></li><li><a href="Tokenizer.html">Tokenizer</a></li><li><a href="TrimNamedEntity.html">TrimNamedEntity</a></li><li><a href="TurkishStemmer.html">TurkishStemmer</a></li><li><a href="Vector.html">Vector</a></li><li><a href="XTable.html">XTable</a></li></ul><h3>Global</h3><ul><li><a href="global.html#endsinArr">endsinArr</a></li><li><a href="global.html#prelude">prelude</a></li><li><a href="global.html#regions">regions</a></li><li><a href="global.html#stem">stem</a></li><li><a href="global.html#stopwords">stopwords</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat Oct 13 2018 19:14:51 GMT+0200 (CEST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>