tag:blogger.com,1999:blog-7232886345252363590.post3230900434627379921..comments2023-09-06T19:01:54.031+03:00Comments on Mihkel's blog: Damerau–Levenshtein distanceMihkel Tiidushttp://www.blogger.com/profile/02312047478961742170noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-7232886345252363590.post-77015255166470166772010-06-09T05:32:22.680+03:002010-06-09T05:32:22.680+03:00Thanks, you saved a bunch of time for me! I've...Thanks, you saved a bunch of time for me! I've added another layer to your code to allow me to compare a string's similarity to another. Usage is:<br /><br />string string1 = "This is a string";<br /><br />string string2 = "Thsi si a stirng";<br /><br />bool thisIsTrue = string1.IsSimilarTo(string2);<br /><br /><br />I divide the the total Dam-Lev distance by the average number of words between the two strings, thus giving an overall 'average' distance of the string or phrase.<br /><br />private static int CountWords(string s)<br />{<br /> MatchCollection collection = Regex.Matches(s, @"[\S]+");<br /> return collection.Count;<br />}<br /><br />public static bool IsSimilarTo(this string string1, string string2)<br />{<br /> string1 = string1.Replace("-", " ").Replace("_", " ").ToLower();<br /> string2 = string2.Replace("-", " ").Replace("_", " ").ToLower();<br /><br /> if (string1.Equals(string2)) { return true; }<br /><br /> float distance = DamerauLevenshteinDistance(string1, string2) / ((CountWords(string1) + CountWords(string2)) / 2);<br /><br /> return distance <= 1.1 ? true : false;<br />}Tyler Sommerhttp://www.lifeclot.netnoreply@blogger.comtag:blogger.com,1999:blog-7232886345252363590.post-74770806527444239692010-03-22T12:29:48.580+02:002010-03-22T12:29:48.580+02:00As explained in the wikipedia entry http://en.wiki...As explained in the wikipedia entry http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance, your algorythm does not actually compute the Damerau-Levenshtein distance. (TO and OST have a distance of 3 in your algorythm, but should have 2).Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7232886345252363590.post-5596434444416637142009-11-16T18:02:13.765+02:002009-11-16T18:02:13.765+02:00This is a great way to handle errors. I've imp...This is a great way to handle errors. I've implemented it along with a URL rewriting method to ensure that if there's a mistake in a URL, the website redirects you to your most likely intended page.<br /><br />Thanks a lot!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7232886345252363590.post-24261991933376533392009-08-25T15:28:40.603+03:002009-08-25T15:28:40.603+03:00Thank you for this great source! It saved some hou...Thank you for this great source! It saved some hours of work ;)KiCHYnoreply@blogger.com