Have ideas to improve npm?Join in the discussion! »

n-gram

1.1.2 • Public • Published

n-gram

Build Coverage Downloads Size

Get n-grams.

Install

npm:

npm install n-gram

Use

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') // []
 
// Anything with a `.length` and `.slice` works: arrays too.
nGram.bigram(['alpha', 'bravo', 'charlie']) // [['alpha', 'bravo'], ['bravo', 'charlie']]

API

nGram(n)

Factory returning a function that converts a given value 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).

License

MIT © Titus Wormer

Install

npm i n-gram

DownloadsWeekly Downloads

20,974

Version

1.1.2

License

MIT

Unpacked Size

5.26 kB

Total Files

4

Last publish

Collaborators

  • avatar
  • avatar