Class: NlpClassifier

NlpClassifier(settings)

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.

Constructor

new NlpClassifier(settings)

Constructor of the class.
Parameters:
Name Type Description
settings Object Settings for this instance.
Source:

Methods

add(srcUtterance, srcIntent)

Adds a new utterance to an intent.
Parameters:
Name Type Description
srcUtterance String Utterance to be added.
srcIntent String Intent for adding the utterance.
Source:

existsUtterance(utterance, intent) → {boolean}

Indicates if an utterance already exists, at the given intent or globally.
Parameters:
Name Type Description
utterance String Utterance to be checked.
intent String Intent to check, undefined to search globally.
Source:
Returns:
True if the intent exists, false otherwise.
Type
boolean

getBestClassification(utterance) → {Object}

Given an utterance, get the label and score of the best classification.
Parameters:
Name Type Description
utterance String Utterance to be classified.
Source:
Returns:
Best classification of the observation.
Type
Object

getClassifications(utterance) → {Array.<Object>}

Get all the labels and score for each label from this utterance.
Parameters:
Name Type Description
utterance String Utterance to be classified.
Source:
Returns:
Sorted array of classifications, with label and score.
Type
Array.<Object>

posUtterance(srcUtterance, intent) → {Number}

Gets the position of a utterance for an intent.
Parameters:
Name Type Description
srcUtterance Object Utterance to be found.
intent Object Intent of the utterance.
Source:
Returns:
Position of the utterance, -1 if not found.
Type
Number

remove(srcUtterance, srcIntent)

Remove an utterance from the classifier.
Parameters:
Name Type Description
srcUtterance String Utterance to be removed.
srcIntent String Intent of the utterance, undefined to search all
Source:

textToFeatures(srcUtterance) → {Array.<Number>}

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.
Parameters:
Name Type Description
srcUtterance String Utterance to be converted to features vector.
Source:
Returns:
Features vector of the utterance.
Type
Array.<Number>

tokenizeAndStem(utterance) → {Array.<String>}

Generate the vector of features.
Parameters:
Name Type Description
utterance String Input utterance.
Source:
Returns:
Vector of features.
Type
Array.<String>

(async) train()

Train the classifier with the existing utterances and intents.
Source: