🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nlp-ngram

frequency-analysis of the terms in a text

0.0.3
latest
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created

a frequency analysis of the terms in a text

it uses nlp-compromise for proper tokenization & normalization

t.ngram({min_count:1, max_size:5})

options.min_count = 1 // throws away seldom-repeated grams
options.max_size = 5 // maximum gram count. prevents the result from becoming gigantic
var nlp = require('nlp_compromise');
var nlpNgram = require('nlp-ngram');
nlp.plugin(nlpNgram);

var t = nlp.text('she said she swims');
t.ngram()
/*
[ [ { word: 'she', count: 2, size: 1 },
    { word: 'said', count: 1, size: 1 },
    { word: 'swims', count: 1, size: 1 } ],
  [ { word: 'she said', count: 1, size: 2 },
    { word: 'said she', count: 1, size: 2 },
    { word: 'she swims', count: 1, size: 2 } ],
  [ { word: 'she said she', count: 1, size: 3 },
    { word: 'said she swims', count: 1, size: 3 } ],
  [ { word: 'she said she swims', count: 1, size: 4 } ] ]
*/

it also takes advantage of the proper tokenization & cleverness of nlp_compromise, ie "Tony Hawk" is one token, not two:

var t = nlp.text(`Tony Hawk played Tony Hawk's pro skater`);
t.ngram()
/*
[ [ { word: 'tony hawk', count: 2, size: 1 },
    { word: 'played', count: 1, size: 1 },
    { word: 'pro', count: 1, size: 1 },
    { word: 'skater', count: 1, size: 1 } ],
  [ { word: 'tony hawk played', count: 1, size: 2 },
    { word: 'played tony hawk', count: 1, size: 2 },
    { word: 'tony hawk pro', count: 1, size: 2 },
    { word: 'pro skater', count: 1, size: 2 } ],
  [ { word: 'tony hawk played tony hawk', count: 1, size: 3 },
    { word: 'played tony hawk pro', count: 1, size: 3 },
    { word: 'tony hawk pro skater', count: 1, size: 3 } ],
  [ { word: 'tony hawk played tony hawk pro', count: 1, size: 4 },
    { word: 'played tony hawk pro skater', count: 1, size: 4 } ] ]
*/
var t = nlp.text(`Tony Hawk played Tony Hawk's pro skater`);
t.ngram({min_count:2})
// [ [ { word: 'tony hawk', count: 2, size: 1 } ], [], [], [] ]

FAQs

Package last updated on 01 Jul 2016

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