Talk:Algorithm Implementation/Strings/Levenshtein distance


 * This page could use a little bit of test code to demonstrate the algorithms do work on some inputs. —The preceding unsigned comment was added by 76.186.105.183 (talk • contribs).

Does anyone recognise the "Teslock" language? I can't find any reference to it aside from this page. Di Gama (talk) 23:14, 28 March 2008 (UTC)

Me either. And it's hard to believe a language that absurdly verbose actually exists. Except if it had been invented specifically to cause repetitive strain injury. --84.184.173.186 (talk) 06:08, 28 January 2009 (UTC)

The alternative C++ algorithm is wrong.

Bug in Python implementation
The current Python implementation works as follows:

>>> levenshtein('cab','ab') 0


 * And I would not call it “pythonic”. It has an abbreviated name, crams the suite of `if`s into the same line, doesn't have spaces around the `+` operators and has a liner longer than 80 characters.  Poor choice of names and three violations of the style guide (PEP008) in four lines.  Python "culture" favors readability over terseness -- this code snippet does not. --BlackJack (talk) 04:57, 3 June 2009 (UTC)

Program doesn't work at all in python3 -rawrgulmuffins (talk) 16:12, 9 April 2015 (UTC)

Bug in vectorized (5th) version
The numpy vectorized Python version incorrectly returns 5 for  (which should be 4 for two 'a' insertions + 2 'd' deletions). The reason is that the deletion step  does not handle the case that the minimum for   could be   due to two consecutive deletions as it is in this example. Can anyone think of a vectorized operation to implement this, or should this step be de-vectorized?

Ruby implementation
The proposed Ruby implementation is awfully slow ! Even unusable... I've found that : http://text.rubyforge.org/classes/Text/Levenshtein.html Do you think we could take the code since it's MIT licence ?

Removed VBA example
I removed the VBA example - it seems to be a copy of this code, which is copyrighted: http://www.planet-source-code.com/URLSEO/vb/scripts/ShowCode!asp/txtCodeId!71576/lngWid!1/anyname.htm and in addition, it removed the header detailing the author and licensing information. 217.204.106.166 (talk) 15:27, 25 March 2010 (UTC)

ABAP implementation
ABAP implementation seems to be not working correctly. I am getting wrong results all the time. Distance "hello" to "hellx" is 4, according to the program...

C implementation
The C implementation is nonstandard. It uses variables to declare arrays rather than constants, and declares arrays after some executable code. It could be rewritten to call alloca and then it would be standard.

Could anyone give an example of how to use the function ?

C++ implementation
It seems wrong. In my opinion it implements the 'Optimal String Alignement' and not the Damerau-Levenshtein, see [].
 * If you look a little closer at that reference, it looks like the 'Optimal String Alignment' actually is the Levenshtein distance, with the additional consideration of the transposition distance. The Damerau-Levenshtein algorithm is more complex, and, as you say, it requires the alphabet size... but I'm not sure I understand what it does. Is it just a more efficient (time-wise) algorithm, or is it doing something more? JoshBowman (discuss • contribs) 07:15, 28 July 2011 (UTC)

The following code does the trick though:

c is the size of the alphabet. I don't know about the other implementations though.