WarMan Posted February 14 Posted February 14 About Levenshtein distance Func _LevenshteinDistance($s1, $s2) Local $len1 = StringLen($s1), $len2 = StringLen($s2) If $len1 = 0 Then Return $len2 If $len2 = 0 Then Return $len1 Local $v0[$len2 + 1], $v1[$len2 + 1] For $i = 0 To $len2 $v0[$i] = $i Next For $i = 0 To $len1 - 1 $v1[0] = $i + 1 For $j = 0 To $len2 - 1 Local $cost = (StringMid($s1, $i + 1, 1) = StringMid($s2, $j + 1, 1)) ? 0 : 1 $v1[$j + 1] = ($v0[$j + 1] + 1 > $v1[$j] + 1 ? $v1[$j] + 1 : $v0[$j + 1] + 1) > $v0[$j] + $cost ? $v0[$j] + $cost : ($v0[$j + 1] + 1 > $v1[$j] + 1 ? $v1[$j] + 1 : $v0[$j + 1] + 1) Next Local $temp = $v0 $v0 = $v1 $v1 = $temp Next Return $v0[$len2] EndFunc
AspirinJunkie Posted February 15 Posted February 15 The following UDF may also be of interest to you, as it expands on the idea of the Levenshtein distance: >>Fuzzy String UDF<<
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now