Skip to content

A library implementing different string similarity and distance measures using Javascript.

Notifications You must be signed in to change notification settings

webhacking/similarity-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

similarity-text

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 Levenshtein where

Levenshtein

where Levenshtein is the indicator function equal to 0 when Levenshtein and equal to 1 otherwise, and Levenshtein 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.

Installation

npm install similarity-text

Usage

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

Contributing

  1. Fork it ( https://github.com/webhacking/similarity-text/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Bug reports and pull requests are welcome on GitHub at https://github.com/webhacking/similarity-text.

About

A library implementing different string similarity and distance measures using Javascript.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published