Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var tmp = [];
var i = 0;
while (true) {
var object = this.trainData[i];
var text = object.text;
var textClass = object.class;
if (this.doTextNormalization) {
text = this.normalize(text)
}
if (this.removeStopWords) {
var newText = '';
var textWords = text.split(' ');
for(var j in textWords) {
if (stopwords.words.indexOf(textWords[j]) === -1) {
newText += textWords[j] + ' ';
}
}
text = newText.trim();
}
if (this.includeStemmedWords) {
var stemmedText = natural.PorterStemmer.stem(text);
// Only include, if such a text isn't already added.
if (this.texts.indexOf(stemmedText) === -1) {
this.trainData.push({
text: stemmedText,
class: textClass,
});
}
const stopwords = require('natural/lib/natural/util/stopwords');
const ClassifierBase = require('natural/lib/natural/classifiers/classifier');
const Classifier = require('./classifier');
const stopwordsBackup = stopwords.words.slice();
class BrainJSClassifier extends ClassifierBase {
constructor (options, stemmer) {
const b = new Classifier(options);
super(b, stemmer);
this.options = options;
}
}
BrainJSClassifier.restore = function (data, options, stemmer) {
var result = new BrainJSClassifier(options || data.options, stemmer);
result.classifier.brain.fromJSON(data.classifier.brain);
result.docs = data.docs;
result.features = data.features;
BrainJSClassifier.enableStopWords = function () {
if (!stopwords.length) {
stopwords.words.push.apply(stopwords.words, stopwordsBackup);
}
};