An open API service indexing awesome lists of open source software.

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.

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.

![Screenshot](http://www.levenshtein.net/images/levenshtein_meilenstein_matrix.gif)

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);