JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 17
  • Score
    100M100P100Q58741F
  • License CC-BY-NC-SA-3.0

The easiest wat to get n-grams from strings

Package Exports

  • simplengrams

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (simplengrams) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

SimleNGrams

The easiest way of getting an array of n-grams from a string!

Useage

const sng = require('simplengrams');
const txt = 'A string of text...';
const bigrams = sng(text, 2);
const trigrams = sng(text, 3);
console.log(bigrams, trigrams);

Errors return an empty two-dimensional array, i.e. [[]]

If the n-gram size (i.e. '2' or '3' in the example above) is greater than the length of the input string, an empty two-dimensional array is returned, i.e. [[]].

Example

Input

const sng = require('simplengrams');
const text = 'In the beginning God created the heavens and the earth.';
const opts = {logs: 3};
const bigrams = sng(text, 2, opts);
console.log(bigrams);

Bigram Output

[
  [ 'In', 'the' ],
  [ 'the', 'beginning' ],
  [ 'beginning', 'God' ],
  [ 'God', 'created' ],
  [ 'created', 'the' ],
  [ 'the', 'heavens' ],
  [ 'heavens', 'and' ],
  [ 'and', 'the' ],
  [ 'the', 'earth' ],
  [ 'earth', '.' ]
]

The Options Object

The options object is optional, the defaults are:

{
  logs: 3
}

'logs'

Number - valid options: 0, 1, 2, 3 (default) Used to control console.log, console.warn, and console.error outputs.

  • 0 = suppress all logs
  • 1 = print errors only
  • 2 = print errors and warnings
  • 3 = print all console logs

License

(C) 2017-18 P. Hughes. All rights reserved.

Shared under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported license.