n-gram
Get n-grams from text
Last updated 5 years ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install n-gram 
SYNC missed versions from official npm registry.

n-gram

Build Coverage Downloads Size

Get n-grams.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install n-gram

Use

import {bigram, trigram, nGram} from 'n-gram'

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

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.
bigram(['alpha', 'bravo', 'charlie']) // [['alpha', 'bravo'], ['bravo', 'charlie']]

API

This package exports the following identifiers: ngram, bigram, and trigram. There is no default export.

nGram(n)

Create a function that converts a given value to n-grams.

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

bigram(value)

Shortcut for nGram(2).

trigram(value)

Shortcut for nGram(3).

License

MIT © Titus Wormer

Current Tags

  • 2.0.1                                ...           latest (5 years ago)

11 Versions

  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.1.2                                ...           6 years ago
  • 1.1.1                                ...           7 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           9 years ago
  • 0.1.2                                ...           11 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
  • 0.0.1                                ...           12 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (10)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |