npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nlp-toolkit

v0.2.6

Published

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.

Downloads

76

Readme

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:

| attribute | type | description | |-----------|------|-------------| | characters | RegExp | regular expression that describes what characters to strip of off (default /[^\w]/g). | | separator | RegExp | regular expression that describes where to split words (default /\s/g). | | eliminateNumbers| boolean | discard tokens that only contain numbers (default false). | | toLowerCase | boolean | transform every token to lower case (default true). | | emptyStrings | boolean | keep 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:

| attribute | type | description | |-----------|------|-------------| | defaultLang | string | default language if processed object does not provide a lang attribute (default en). | | additionalWords | object | add additional stopwords to the list of stopwords |

additionalWords:

| attribute | type | description | |-----------|------|-------------| | all | array | list of stopwords to add to every language | | default | array | list of stopwords if language is not supported | | lang | array | list 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:

| attribute | type | description | |-----------|------|-------------| | defaultStemmer | string | default 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())