1.0.0 • Published 6 years ago

@joogl/js-levenshtein-opt v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

js-levenshtein-opt

A fork of js-levenshtein adding a threshold after which the original algorithm will stop calculating the distance between two inputs.

Install

$ npm i @joogl/js-levenshtein-opt

Usage

const levenshtein = require('js-levenshtein-opt');

// Original algorithm available without a third argument.
levenshtein('kitten', 'sitting'); // => 3

// Adding a limitation will stop the calculation as soon as the limit is met.
levenshtein('kitten', 'sitting', 5); // => 3
levenshtein('kitten', 'ambiguous', 5); // => 5

Benchmark

TestLimit 0 opsLimit 3 opsLimit 5 opsLimit 10 ops
Paragraphs123209,363222,938216,120
Sentences2,374561,027207,529112,869
Words2,3899,7976,1152,106

These benchmarks were done in the integrated test suite on a Ryzen 7 1700 Eight-Core @ 3 GHz and Node v8.11.1.

The package provides significant performance boosts for paragraphs and sentences. Distance calculation for words can be sped up to 5 times, but declines quickly the higher the limit. If comparing single words, it is recommended to use the algorithm without limitation starting at a distance limit of 10.

License

MIT © Gustaf Andersson