https://github.com/thinkphp/string.levenshtein
A String.method MooTools which calculates Levenshtein distance between two strings.
https://github.com/thinkphp/string.levenshtein
Last synced: 5 months ago
JSON representation
A String.method MooTools which calculates Levenshtein distance between two strings.
- Host: GitHub
- URL: https://github.com/thinkphp/string.levenshtein
- Owner: thinkphp
- Created: 2010-10-06T07:38:05.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2010-10-25T08:09:57.000Z (over 15 years ago)
- Last Synced: 2025-08-02T08:26:21.200Z (6 months ago)
- Language: JavaScript
- Homepage: http://thinkphp.ro/apps/js-hacks/String.levenshtein/String.levenshtein.html
- Size: 102 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
String.levenshtein
==================
This method calculates Levenshtein distance between two strings. In information theory and computer
science, the Levenshtein distance is a metric for measuring the amount of difference between two
sequences (called edit distance). The Levenshtein distance between two strings is given by minimum
number of operations needed to transform one string into another given string, where possible operations
are insertion, deletion, or substitution of a single character.
The Levenshtein distance algorithm has been used in:
* Spell checking
* Speech recognition
* DNA analysis
* plagiarism detection
The complexity of the algorithm is O(mXn), where n and m are the length of string1 and string2.

How to use
----------
First you must to include the JS files in the head of your HTML document.
#HTML
In your JavaScript code.
#JavaScript
var words = ["rodion","dunia","raskolnikov","adrian","statescu","sunday","saturday","jquery","mootools","dojo"];
function matchWords(input) {
return words.filter(function(word){
//calculates levenshtein distance
var lev = word.levenshtein(input);
//in this case the distance is in the iterval [0,1,2,3];
if(lev >=0 && lev <= 3 ) {
return word;
}
});
}
var input = "rascolnicov";
var similarities = matchWords(input);
if(window.console) console.log("Did you mean: " + similarities);
var similar = matchWords("motols");
if(window.console) console.log("Did you mean: " + similar);