predictionary
Version:
JavaScript dictionary-based word prediction library.
3,853 lines (991 loc) • 66.5 kB
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: Predictionary</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: Predictionary</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>Predictionary<span class="signature">()</span><span class="type-signature"></span></h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="Predictionary"><span class="type-signature"></span>new Predictionary<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Constructs a Predictionary word prediction class. It's possible to manage multiple internal dictionaries, retrieve predictions
(suggestions) for a given input and learn/refine the dictionaries from user input.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line13">line 13</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="DEFAULT_DICTIONARY_KEY"><span class="type-signature"></span>DEFAULT_DICTIONARY_KEY<span class="type-signature"> :string</span></h4>
<div class="description">
Default dictionary key, if no key is specified.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line18">line 18</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id=".instance"><span class="type-signature">(static) </span>instance<span class="signature">()</span><span class="type-signature"> → {<a href="Predictionary.html">Predictionary</a>}</span></h4>
<div class="description">
Constructs a new instance of Predictionary
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line531">line 531</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Predictionary.html">Predictionary</a></span>
</dd>
</dl>
<h4 class="name" id="addDictionary"><span class="type-signature"></span>addDictionary<span class="signature">(dictionaryKey, words<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Add a new internal dictionary for predictions.
</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>dictionaryKey</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">the key of the dictionary to add</td>
</tr>
<tr>
<td class="name"><code>words</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">Optional array of words (string) that should be added to the new dictionary.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line133">line 133</a>
</li></ul></dd>
</dl>
<h4 class="name" id="addWord"><span class="type-signature"></span>addWord<span class="signature">(element, dictionaryKey<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Add a single new word/element to a dictionary.
</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>element</code></td>
<td class="type">
<span class="param-type">string</span>
|
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">the element to add, can be either a plain word as a string or an object containing
the properties object.word (word to add as string) and object.rank (number specifying the rank of the word,
a lower rank causes the word to be ranked to front as a suggestion).</td>
</tr>
<tr>
<td class="name"><code>dictionaryKey</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
<a href="Predictionary.html#DEFAULT_DICTIONARY_KEY">Predictionary#DEFAULT_DICTIONARY_KEY</a>
</td>
<td class="description last">optional key of the dictionary to add the element.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line156">line 156</a>
</li></ul></dd>
</dl>
<h4 class="name" id="addWords"><span class="type-signature"></span>addWords<span class="signature">(elements, dictionaryKey<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Add multiple new words/elements to a dictionary.
</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>elements</code></td>
<td class="type">
<span class="param-type">string</span>
|
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">the elements to add, can be an Array of either plain words (string) or of objects containing
the properties object.word (word to add as string) and object.rank (number specifying the rank of the word,
a lower rank causes the word to be ranked to front as a suggestion).</td>
</tr>
<tr>
<td class="name"><code>dictionaryKey</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
<a href="Predictionary.html#DEFAULT_DICTIONARY_KEY">Predictionary#DEFAULT_DICTIONARY_KEY</a>
</td>
<td class="description last">optional key of the dictionary to add the element.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line180">line 180</a>
</li></ul></dd>
</dl>
<h4 class="name" id="applyPrediction"><span class="type-signature"></span>applyPrediction<span class="signature">(input, chosenPrediction, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
Apply chosen suggestion to a given input, e.g. input = "this is an ap" and chosenPrediction = "Apple" results in
"this is an Apple". Calling this function automatically refines the saved frequency of the chosen word making it
more likely to be suggested in the future.
</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>input</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">the current input string (e.g. from textfield)</td>
</tr>
<tr>
<td class="name"><code>chosenPrediction</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">the chosen prediction which should be applied to the input string</td>
</tr>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">options object containing additional properties.
<h6>Properties</h6>
<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>addToDictionary</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">the key of the dictionary where new learned words should be added. If not
set the dictionary to add is automatically determined.</td>
</tr>
<tr>
<td class="name"><code>shouldCompleteLastWord</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">if true the last word is completed, if false the chosen prediction
is added as new word. If not set this decision is done automatically (last character is space -> new word).</td>
</tr>
<tr>
<td class="name"><code>dontLearn</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">if true the chosen predictions are not added or their frequencies updated</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line350">line 350</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
the given input with the applied suggestion
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h4 class="name" id="delete"><span class="type-signature"></span>delete<span class="signature">(inputOrWord, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Deletes a single word from one or all dictionaries.
</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>inputOrWord</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">a single word or longer string where the last word will be deleted in the dictionaries.</td>
</tr>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">Object for options
<h6>Properties</h6>
<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>dictionaryKey</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">the key of the dictionary where the word should be deleted. If not
specified the word is deleted in all dictionaries.</td>
</tr>
<tr>
<td class="name"><code>ignoreCase</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">if false or undefined (default) only words with matching cases are
deleted, otherwise also words with non-matching case.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line199">line 199</a>
</li></ul></dd>
</dl>
<h4 class="name" id="dictionariesToJSON"><span class="type-signature"></span>dictionariesToJSON<span class="signature">()</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
Exports all dictionaries to a JSON string. Subsequently the dictionaries can be imported using the resulting string
and <a href="Predictionary.html#loadDictionaries">Predictionary#loadDictionaries</a>.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line79">line 79</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
JSON string representing all currently loaded dictionaries.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h4 class="name" id="dictionaryToJSON"><span class="type-signature"></span>dictionaryToJSON<span class="signature">(dictionaryKey<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
Exports a single dictionary to a JSON string. Subsequently the dictionary can be imported using the resulting string
and <a href="Predictionary.html#loadDictionary">Predictionary#loadDictionary</a>.
</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>dictionaryKey</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
<a href="Predictionary.html#DEFAULT_DICTIONARY_KEY">Predictionary#DEFAULT_DICTIONARY_KEY</a>
</td>
<td class="description last">the key of the dictionary to export.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line67">line 67</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
JSON string representing the currently loaded dictionary with specified dictionaryKey.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h4 class="name" id="getDictionaryKeys"><span class="type-signature"></span>getDictionaryKeys<span class="signature">(onlyEnabled<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Array.<string>}</span></h4>
<div class="description">
Returns a list of currently loaded dictionary keys.
</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>onlyEnabled</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">if true only keys of dictionaries that are enabled are returned. See e.g.
<a href="Predictionary.html#useDictionaries">Predictionary#useDictionaries</a></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line453">line 453</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.<string></span>
</dd>
</dl>
<h4 class="name" id="getWords"><span class="type-signature"></span>getWords<span class="signature">(dictionaryKey<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Array.<string>}</span></h4>
<div class="description">
Retrieves saved words of a single or all loaded dictionaries.
</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>dictionaryKey</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">key of the dictionary from which the words should be retrieved, if not set all
dictionaries are used.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line265">line 265</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
array of saved words (string) for the dictionary with the given key.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.<string></span>
</dd>
</dl>
<h4 class="name" id="hasWord"><span class="type-signature"></span>hasWord<span class="signature">(word, dictionaryKey<span class="signature-attributes">opt</span>, matchCase<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
Test if a given word exists a single or all loaded dictionaries.
</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>word</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">to test if existing</td>
</tr>
<tr>
<td class="name"><code>dictionaryKey</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">key of the dictionary to check, if not set all dictionaries are used</td>
</tr>
<tr>
<td class="name"><code>matchCase</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">if set (true) the word is searched case-sensitive, otherwise case-insensitive (default)</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line285">line 285</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
true if the given word is existing
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="isUsingOnlyDefaultDictionary"><span class="type-signature"></span>isUsingOnlyDefaultDictionary<span class="signature">()</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
Returns true if only the default dictionary is used (key <a href="Predictionary.html#DEFAULT_DICTIONARY_KEY">Predictionary#DEFAULT_DICTIONARY_KEY</a>).
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line464">line 464</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="learn"><span class="type-signature"></span>learn<span class="signature">(chosenWord, previousWord<span class="signature-attributes">opt</span>, addToDictionary<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Updates the frequencies for given words, making them to be more likely suggested in the future.
</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>chosenWord</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">a suggestion/word the user has chosen</td>
</tr>
<tr>
<td class="name"><code>previousWord</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">the previous word of the chosen suggestion</td>
</tr>
<tr>
<td class="name"><code>addToDictionary</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">the key of the dictionary where new words should be added. Automatically determined, if 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="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line374">line 374</a>
</li></ul></dd>
</dl>
<h4 class="name" id="learnFromInput"><span class="type-signature"></span>learnFromInput<span class="signature">(input, dictionaryKey<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
Learns from input text while the user is typing. This method can be called with e.g. the value of a text input
field for every character the user is typing.
</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>input</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">the text string to learn with. The second last and third last words are learned.</td>
</tr>
<tr>
<td class="name"><code>dictionaryKey</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">the key of the dictionary where new words should be added. Automatically determined, if 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="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line415">line 415</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
true if something was learned, false if not
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="learnFromText"><span class="type-signature"></span>learnFromText<span class="signature">(text, dictionaryKey<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Learns words and transitions from a given text/phrase.
</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 text to learn from</td>
</tr>
<tr>
<td class="name"><code>dictionaryKey</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
<a href="Predictionary.html#DEFAULT_DICTIONARY_KEY">Predictionary#DEFAULT_DICTIONARY_KEY</a>
</td>
<td class="description last">the key of the dictionary where the words should
be learned/added.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line435">line 435</a>
</li></ul></dd>
</dl>
<h4 class="name" id="loadDictionaries"><span class="type-signature"></span>loadDictionaries<span class="signature">(dictionariesJSON)</span><span class="type-signature"></span></h4>
<div class="description">
Loads all dictionaries from a JSON string that was previously exported by <a href="Predictionary.html#dictionariesToJSON">Predictionary#dictionariesToJSON</a>.
This method replaces/deletes all currently loaded dictionaries!
</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>dictionariesJSON</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">json string representing dictionaries, exported by <a href="Predictionary.html#dictionariesToJSON">Predictionary#dictionariesToJSON</a></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line49">line 49</a>
</li></ul></dd>
</dl>
<h4 class="name" id="loadDictionary"><span class="type-signature"></span>loadDictionary<span class="signature">(dictionaryJSON, dictionaryKey<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Loads a single dictionary from a JSON string that was previously exported by <a href="Predictionary.html#dictionaryToJSON">Predictionary#dictionaryToJSON</a>.
If the given dictionaryKey already exists, the existing dictionary is replaced.
</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>dictionaryJSON</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">json string representing a dictionary, exported by <a href="Predictionary.html#dictionaryToJSON">Predictionary#dictionaryToJSON</a></td>
</tr>
<tr>
<td class="name"><code>dictionaryKey</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
<a href="Predictionary.html#DEFAULT_DICTIONARY_KEY">Predictionary#DEFAULT_DICTIONARY_KEY</a>
</td>
<td class="description last">the key for which the dictionary should
be imported.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line34">line 34</a>
</li></ul></dd>
</dl>
<h4 class="name" id="parseWords"><span class="type-signature"></span>parseWords<span class="signature">(importString, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Import words from a plain string (e.g. text file).
</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>importString</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">a plain text string (e.g. from a text file)</td>
</tr>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">options object containing additional properties. The default properties are suited for
a plain text string in format: "word1;word2;word3;...", setting rankPosition=1 would be suited for
a plain text in format: "word1 rank1;word2 rank2;word3 rank3;...".
<h6>Properties</h6>
<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>elementSeparator</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">separator to split the elements from the importString</td>
</tr>
<tr>
<td class="name"><code>rankSeparator</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
<space>
</td>
<td class="description last">separator to split a single element into word and rank</td>
</tr>
<tr>
<td class="name"><code>wordPosition</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
0
</td>
<td class="description last">position of the word in the element (0-based)</td>
</tr>
<tr>
<td class="name"><code>rankPosition</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">position of the rank in the element (0-based)</td>
</tr>
<tr>
<td class="name"><code>addToDictionary</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
<a href="Predictionary.html#DEFAULT_DICTIONARY_KEY">Predictionary#DEFAULT_DICTIONARY_KEY</a>
</td>
<td class="description last">key of the dictionary where
the words should be added.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line227">line 227</a>
</li></ul></dd>
</dl>
<h4 class="name" id="predict"><span class="type-signature"></span>predict<span class="signature">(input, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Array.<string>}</span></h4>
<div class="description">
Returns word suggestions for a given input. Automatically detects if the la