utils.edit_distance

Returns the Levenshtein Edit Distance between two words

Prototype

n = utils.edit_distance (word1, word2)

Description

This returns the Levenshtein Edit Distance between the two words. This is the same behaviour as the world.EditDistance function.

This could be used in a spell checker to work out how close a misspelt word is to a correctly spelt one.

eg.

print (utils.edit_distance ("food", "fodder"))  --> 3
The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character.

For example, the Levenshtein distance between "kitten" and "sitting" is 3, since the following three edits change one into the other, and there is no way to do it with fewer than three edits:

   1. kitten --> sitten (substitution of 's' for 'k')
   2. sitten --> sittin (substitution of 'i' for 'e')
   3. sittin --> sitting (insert 'g' at the end).

Lua functions

Topics