Levenshtein
Ruby
About
Note: This is now part of the Text project, hosted on RubyForge. For newer releases, visit Text on RubyForge.
The Levenshtein distance is a measure of how similar two strings s and t are, calculated as the number of deletions/insertions/substitutions needed to transform s into t. The greater the distance, the more the strings differ.
The Levenshtein distance is also sometimes referred to as the easier-to-pronounce-and-spell ‘edit distance’.
Revision history
- 2005-05-19 1.3 Repairing an oversight, distance can now be called via
Levenshtein.distance(s, t) - 2005-05-04 1.2 Now uses just one 1-dimensional array. I think this is as far as optimisation can go.
- 2005-05-04 1.1 Now storing only the current and previous rows of the matrix instead of the whole lot.
Licence
Copyright © 2005 Paul Battley
Usage of the works is permitted provided that this instrument is retained with the works, so that any entity that uses the works is notified of this instrument.
DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
Download
2005-07-26 15:22 UTC. Comments: 2.
nieruihan
Wrote at 2005-08-26 05:39 UTC using Firefox 1.0.6 on Windows XP:
Hi,The link to levenshtein.rb (http://po-ru.com/files/levenshtein/1.2/levenshtein.rb) returns:
Not Found
The requested URL /files/levenshtein/1.2/levenshtein.rb was not found on this server.
Paul Battley
Wrote at 2005-08-26 10:08 UTC using Safari 412.2.2 on Mac OS X:
Thanks. It should be fixed now.