A library implementing different string similarity and distance measures using Javascript.
Calculates the similarity between strings x and y using levenshtein distance.
Mathematically, the Levenshtein distance between two strings
a
and b
(of length |a|
and |b|
respectively) is given by
where
where
is the indicator function equal to 0
when
and equal to 1 otherwise, and
is the distance between the first i
characters of a
and the first
j
characters of b
.
Note that the first element in the minimum corresponds to
deletion (from a
to b
), the second to insertion and
the third to match or mismatch, depending on whether the
respective symbols are the same.
npm install similarity-text
import {similarityPercent} from 'similarity-text';
const percent1 = similarityPercent('영준아 학교가야지', '영준아 밥먹어야지');
const percent2 = similarityPercent('朝に目が覚めると、何故か泣いている', '見ていた 初め 夢は');
const percent3 = similarityPercent('Please don’t eat me!! I have a wife and kids. Eat them!', 'If something’s hard to do, then it’s not worth doing');
console.log('percent1', percent1);
console.log('percent2', percent2);
console.log('percent2', percent3);
// Output
// percent1 66.67
// percent2 0
// percent2 16.36
- Fork it ( https://github.com/webhacking/similarity-text/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Bug reports and pull requests are welcome on GitHub at https://github.com/webhacking/similarity-text.