VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Quick Levenshtein Edit Distance

Larry Lewis  (1 Submission)   String Manipulation   Visual Basic 5.0   Advanced   Wed 3rd February 2021

Levenshtein edit distance is a measure of the similarity between two strings. Edit distance is the the minimum number of character deletions, insertions, substitutions, and transpositions required to transform string1 into string2. In essence, the function is used to perform a fuzzy or approximate string search. This is very handy for trying to find the "correct" string for one that has been entered incorrectly, mistyped, etc. The code has been optimized to find strings that are very similar. A "limit" parameter is provided so the function will quickly reject strings that contain more than k mismatches.

Inputs
s as string, t as string, limit as integer 'maximum edit distance

Assumes
This code takes character transpositions into account when calculating edit distance (If desired, the transposition code can be commented out). The limit parameter provides a significant performance gain (over 10x faster) over standard implementations when searching for highly similar strings.

Returns
Returns the integer edit distance (minimum number of character deletions, insertions, substitutions, and transpositions) required to transform string1 into string2 where edit distance is <= limit. Otherwise returns (len(s) + len(t)).

Rate Quick Levenshtein Edit Distance (4(4 Vote))
Quick Levenshtein Edit Distance.bas

Quick Levenshtein Edit Distance Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters