How to use the natural/lib/natural/util/stopwords.words function in natural

To help you get started, we’ve selected a few natural examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bobalazek / synaptic-simple-trainer / lib / index.js View on Github external
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,
                    });
                }
github mysamai / natural-brain / lib / index.js View on Github external
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;
github mysamai / natural-brain / lib / index.js View on Github external
BrainJSClassifier.enableStopWords = function () {
  if (!stopwords.length) {
    stopwords.words.push.apply(stopwords.words, stopwordsBackup);
  }
};

natural

General natural language (tokenizing, stemming (English, Russian, Spanish), part-of-speech tagging, sentiment analysis, classification, inflection, phonetics, tfidf, WordNet, jaro-winkler, Levenshtein distance, Dice's Coefficient) facilities for node.

MIT
Latest version published 1 month ago

Package Health Score

98 / 100
Full package analysis