node-nlp
Version:
Library for NLU (Natural Language Understanding) done in Node.js
1,547 lines (363 loc) • 18.9 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: Classifier</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: Classifier</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>Classifier<span class="signature">(settings)</span><span class="type-signature"></span></h2>
<div class="class-description">Class for a generic classifier.
This is an abstract class that must be implemented by subclasses that
contains the real classifier algorithm.</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="Classifier"><span class="type-signature"></span>new Classifier<span class="signature">(settings)</span><span class="type-signature"></span></h4>
<div class="description">
Constructor of the class.
Initialize the basic properties and structure of any 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>settings</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">Settings for initializing the instance.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classifiers_classifier.js.html">classifiers/classifier.js</a>, <a href="classifiers_classifier.js.html#line29">line 29</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="addLabel"><span class="type-signature"></span>addLabel<span class="signature">(label)</span><span class="type-signature"> → {Array.<String>}</span></h4>
<div class="description">
Adds a new label to the observation tree. If the label already exists,
return the existing one without creating it again.
</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>label</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Label to be created or getted.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classifiers_classifier.js.html">classifiers/classifier.js</a>, <a href="classifiers_classifier.js.html#line57">line 57</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
List of observations assigned to this label.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.<String></span>
</dd>
</dl>
<h4 class="name" id="addObservation"><span class="type-signature"></span>addObservation<span class="signature">(observation, label)</span><span class="type-signature"></span></h4>
<div class="description">
Adds a new observation to 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>observation</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Observation to be added.</td>
</tr>
<tr>
<td class="name"><code>label</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Label of the observation.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classifiers_classifier.js.html">classifiers/classifier.js</a>, <a href="classifiers_classifier.js.html#line70">line 70</a>
</li></ul></dd>
</dl>
<h4 class="name" id="classifyObservation"><span class="type-signature"></span>classifyObservation<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Classify one observation.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classifiers_classifier.js.html">classifiers/classifier.js</a>, <a href="classifiers_classifier.js.html#line130">line 130</a>
</li></ul></dd>
</dl>
<h4 class="name" id="clear"><span class="type-signature"></span>clear<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Clears the content of the instance.
This is done by initializing the observations object, the labels array
and the observation count.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classifiers_classifier.js.html">classifiers/classifier.js</a>, <a href="classifiers_classifier.js.html#line45">line 45</a>
</li></ul></dd>
</dl>
<h4 class="name" id="createClassificationMatrix"><span class="type-signature"></span>createClassificationMatrix<span class="signature">()</span><span class="type-signature"> → {Array.<Array.<Number>>}</span></h4>
<div class="description">
Creates a matrix filled with zeros, that relate every single observation
with every single label.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classifiers_classifier.js.html">classifiers/classifier.js</a>, <a href="classifiers_classifier.js.html#line166">line 166</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
A bidimensional array where x is the observation
and y is the label, filled to zeros.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.<Array.<Number>></span>
</dd>
</dl>
<h4 class="name" id="getBestClassification"><span class="type-signature"></span>getBestClassification<span class="signature">(observation)</span><span class="type-signature"> → {Object}</span></h4>
<div class="description">
Given an observation, 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>observation</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Observation 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="classifiers_classifier.js.html">classifiers/classifier.js</a>, <a href="classifiers_classifier.js.html#line152">line 152</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">(observation)</span><span class="type-signature"> → {Array.<Object>}</span></h4>
<div class="description">
Get all the labels and score for each label from one observation.
</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>observation</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Observation 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="classifiers_classifier.js.html">classifiers/classifier.js</a>, <a href="classifiers_classifier.js.html#line141">line 141</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Sorted array of classifications, that means label and the score.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.<Object></span>
</dd>
</dl>
<h4 class="name" id="recalculateObservationCount"><span class="type-signature"></span>recalculateObservationCount<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Iterate all the observations to calculate the total observation count.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classifiers_classifier.js.html">classifiers/classifier.js</a>, <a href="classifiers_classifier.js.html#line117">line 117</a>
</li></ul></dd>
</dl>
<h4 class="name" id="removeObservation"><span class="type-signature"></span>removeObservation<span class="signature">(observation, label)</span><span class="type-signature"></span></h4>
<div class="description">
Removes an observation. The label of the observation can be passed or
can be omitted. When omitted, it loops over all labels tryin to remove
the given observation.
</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>observation</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Observation to be removed.</td>
</tr>
<tr>
<td class="name"><code>label</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Label of the observation, or undefined to iterate over
all labels.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classifiers_classifier.js.html">classifiers/classifier.js</a>, <a href="classifiers_classifier.js.html#line104">line 104</a>
</li></ul></dd>
</dl>
<h4 class="name" id="removeObservationByLabel"><span class="type-signature"></span>removeObservationByLabel<span class="signature">(observation, label)</span><span class="type-signature"></span></h4>
<div class="description">
Removes an observation from the observation list of a label.
</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>observation</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Observation to be removed.</td>
</tr>
<tr>
<td class="name"><code>label</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Label where we want the observation to be removed.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classifiers_classifier.js.html">classifiers/classifier.js</a>, <a href="classifiers_classifier.js.html#line81">line 81</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>