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

n-gram

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

n-gram

Get n-grams from text

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

n-gram Build Status Coverage Status

Get n-grams in JavaScript.

Installation

npm:

$ npm install n-gram

Component:

$ component install wooorm/n-gram

Bower:

$ bower install n-gram

Usage

var nGram = require('n-gram');

nGram.bigram('n-gram'); // ['n-', '-g', 'gr', 'ra', 'am']
nGram(2)('n-gram'); // ['n-', '-g', 'gr', 'ra', 'am']

nGram.trigram('n-gram'); // ['n-g', '-gr', 'gra', 'ram']

nGram(6)('n-gram'); // ['n-gram']
nGram(7)('n-gram'); // []

API

nGram(n)

Factory returning a function that converts a given string to n-grams.

Want padding? Use something like the following: nGram(2)(' ' + value + ' ');

nGram.bigram(value)

Shortcut for nGram(2)

nGram.trigram(value)

Shortcut for nGram(3)

Benchmark

$ npm run install-benchmark # Just once of course.
$ npm run benchmark

On a MacBook Air, it runs about 506,112 op/s on a ssentence.

               nGram -- this module
  584,668 op/s »   bigrams on a sentence
    4,607 op/s »   bigrams on an article
  566,130 op/s »  trigrams on a sentence
    4,558 op/s »  trigrams on an article
  498,405 op/s » ten-grams on a sentence
    4,085 op/s » ten-grams on an article

               madbence/ngram
  489,280 op/s »   bigrams on a sentence
    8,747 op/s »   bigrams on an article
  487,999 op/s »  trigrams on a sentence
    8,901 op/s »  trigrams on an article
  533,071 op/s » ten-grams on a sentence
    7,788 op/s » ten-grams on an article

               ngram
  359,137 op/s »   bigrams on a sentence
    5,634 op/s »   bigrams on an article
  365,814 op/s »  trigrams on a sentence
    5,186 op/s »  trigrams on an article
  367,451 op/s » ten-grams on a sentence
    4,781 op/s » ten-grams on an article

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 17 Oct 2014

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