ngrammer
v0.1.0
Published
Frequency analysis for javascript code
Downloads
3
Readme
ngrammer
Perform frequency analysis on a js code string
Uses nlp-compromise with nlp-ngram
Installation
node.js
Install using npm:
$ npm install ngrammer
Examples
Node.JS
const ngrammer = require('ngrammer');
const fs = require('fs');
const fileContents = fs.readFileSync('./testfile.js').toString();
/*
options:
- minCount: minimum gram frequency, default: 10
- maxSize: max gram count, default: 3
*/
const ngram = ngrammer(fileContents, { minCount: 10, maxSize: 3 })
/*
[
[
{ word: 'someword', count: 100, size: 1 },
{ word: 'another', count: 90, size: 1 },
{ word: 'etc', count: 80, size: 1 },
...
],
[
{ word: 'two words', count: 30, size: 2 },
{ word: 'some more', count: 20, size: 2 },
{ word: 'etc etc', count: 10, size: 2 },
...
],
...
]
*/
Testing
To run the tests:
$ npm test
Contributing
Feel free to create a pull request.
License
MIT - see LICENSE