ngrams
nodejs module for searching by Ngram similarity of characters. An emitation of the python NGram module
basic usage
var NGrams = ;var n = //default N=3 (size of ngram) w=1 (warp, use greater than 1 to increase the similarity of shorter string pairs)n; //add single itemsn; //or an array of itemsconsole; // second argument is optional - threshold - return only items with similarity greater than threshold. default is 0/*will output an array of items with similarity greater than threshold ordered by similarity//[{ item: "spam", similarity: 0.375}, { item: "span", similarity: 0.375}]*/ n; /*returns the item with the maximum ngram similarity or undefined if none{ item: "spam", similarity: 1.0}*/
more usage examples
var n = 2; //create ngrams of size 2n; //returns " word " padding is of size N-1n;/*returns the ngrams of the item "ab" after padding[ [' ', 'a'], ['a', 'b'], ['b', ' ']]*/ n;/*returns all the ngrams that both items share:[ [' ', 'a'], ['a', 'b']]*/n; // returns 2n;/*returns{ all: 8, //count of all ngrams in both items same: 2, //ngrams sahred by both items distinct: 6, //count of distinct ngrams in total diff: 4 //count of unique ngrams - which do not appear in both items}*/n; //third argument is warp - optional, default is 1 /*returns 0.3333333333333333formula is: ((distinct ^ warp)-(diff ^ warp))/(distinct^warp)*/
for more use cases look at test.js