Created
October 13, 2017 14:11
-
-
Save corporatepiyush/51649089a076456ea4bf2e00ed9ab3eb to your computer and use it in GitHub Desktop.
Ngrams Generators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('ramda') | |
const ngrams = function (string) { | |
var r = []; | |
for (var n = 2; n <= string.length; n++) | |
for (var i = 0; i <= string.length - n; i++) | |
r.push(string.substring(i, i + n)); | |
return r; | |
} | |
const ngramsForStatement = function(statement) { | |
const words = statement.replace(',', '').split(' ') | |
const allngrams = words.map(function(word) { | |
return ngrams(word) | |
}); | |
return _.uniq(_.flatten(allngrams)) | |
} | |
console.log(ngramsForStatement("COSTA, COFFEE")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment