Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nlp-toolkit

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nlp-toolkit

This module covers some basic nlp principles and implementations. Every implementation in this module is written as stream to only hold that data in memory that is currently processed at any step.

  • 0.2.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Natural Language Processing Toolkit for node.js

This module covers some basic nlp principles and implementations. The main focus is performance. When we deal with sample or training data in nlp, we quickly run out of memory. Therefore every implementation in this module is written as stream to only hold that data in memory that is currently processed at any step.

Install

npm install nlp-toolkit

Example

Frequency distribution of words in texts. Tokenize, remove stopwords, stem words, count words. Traditionally those steps happen sequentially. But we do not need to tokenize the whole text before removing stopwords.

var nlp = require('nlp-toolkit');
var fs = require('fs');
var es = require('event-stream');

fs.createReadStream('./pride_prejudice.txt')
.pipe(es.split())
.pipe(nlp.tokenizer())
.pipe(nlp.stopwords())
.pipe(nlp.stemmer())
.pipe(nlp.frequency())
.on('data', function (freqDist) {
  console.log(freqDist.slice(0, 10));
})
.on('error', function (err) {
  console.error(err);
});

Modules

Tokenizer

.pipe(nlp.tokenizer(options))

options:

attributetypedescription
charactersRegExpregular expression that describes what characters to strip of off (default /[^\w]/g).
separatorRegExpregular expression that describes where to split words (default /\s/g).
eliminateNumbersbooleandiscard tokens that only contain numbers (default false).
toLowerCasebooleantransform every token to lower case (default true).
emptyStringsbooleankeep empty string when through some previous steps tokens result in length === 0 (default false).

Tokenizer also work in a non-stream context:

var tokens = nlp.tokenizer(string, options);

Stopwords

.pipe(nlp.stopwords(options))

options:

attributetypedescription
defaultLangstringdefault language if processed object does not provide a lang attribute (default en).
additionalWordsobjectadd additional stopwords to the list of stopwords

additionalWords:

attributetypedescription
allarraylist of stopwords to add to every language
defaultarraylist of stopwords if language is not supported
langarraylist of stopwords specific to lang

Supported languages: da, de, en, es, fi, fr, hu, it, nl, no, pt, ro, ru, se, tr.

Stopwords also work in a non-stream context:

nlp.stopwords(sentence, options)
.then(function (tokens) {}})
.catch(function (err) { console.error(err); });

Stemmer

.pipe(nlp.stemmer(options))

options:

attributetypedescription
defaultStemmerstringdefault stemmer for language if processed object does not provide a lang attribute (default en).

Supported languages: da, de, en, es, fi, fr, hu, it, nl, no, pt, ro, ru, se, tr.

Stopwords also work in a non-stream context:

var tokens = nlp.stemmer(sentence, options);

This module uses the stemmer implementation of Snowball-Stemmer.

Frequency Distribution

.pipe(nlp.frequency())

Keywords

FAQs

Package last updated on 11 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc