plugin for nlp-compromise
npm install compromise-ngramsnpm install compromise-ngrams``js
const nlp = require('compromise')
nlp.extend(require('compromise-ngrams'))
let doc = nlp(bake 'em away, toys)
doc.bigrams().data()
//[{normal:'bake em', size:2, count:1}, {normal:'em away', size:2, count:1}, {normal:'em toys', size:2, count:1}]
//same for:
doc.unigrams()
doc.trigrams()
doc.ngrams({ size: 3 })
``
- .ngrams({}) - list all repeating sub-phrases, by word-count
- .unigrams(n) - n-grams with one word
- .bigrams(n) - n-grams with two words
- .trigrams(n) - n-grams with three words
- .startgrams({}) - n-grams including the first term of a phrase
- .endgrams({}) - n-grams including the last term of a phrase
- .edgegrams({}) - n-grams including the first or last term of a phrase
MIT