10

I need to implement some kind of this:

string textToSearch = "Extreme Golf: The Showdown";
string textToSearchFor = "Golf Extreme Showdown";
int fuzzyMatchScoreThreshold = 80; // One a 0 to 100 scale
bool searchSuccessful = IsFuzzyMatch(textToSearch, textToSearchFor, fuzzyMatchScoreThreshold);
if (searchSuccessful == true)
{
    -- we have a match.
}

Here's the function stub written in C#:

public bool IsFuzzyMatch (string textToSearch, string textToSearchFor, int fuzzyMatchScoreThreshold)
{
   bool isMatch = false;
   // do fuzzy logic here and set isMatch to true if successful match.
   return isMatch;
}

But I have no any idea how to implement logic in IsFuzzyMatch method. Any ideas? Perhaps there is a ready-made solution for this purpose?

MrLore
  • 3,759
  • 2
  • 28
  • 36
Nazar Grynko
  • 101
  • 1
  • 3
  • 1
    You could calculate the [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance), using words as symbols instead of characters, where words are considered equal based on their Levenshtein distance. There are [many SO topics](http://stackoverflow.com/search?q=[c%23]+Levenshtein+distance) on the Levenshtein distance. – dtb Nov 03 '10 at 11:15
  • See http://stackoverflow.com/questions/451884/similar-string-algorithm/451910#451910 – Jeff Moser Nov 03 '10 at 12:24

2 Answers2

9

I like a combination of Dice Coeffiecient, Levenshtein Distance, Longest Common Subsequence, and at times the Double Metaphone. The first three will provide you a threshold value. I prefer to combine them in some way. YMMV.

I've just posted a blog post that has a C# implementation for each of these called Four Functions for Finding Fuzzy String Matches in C# Extensions.

DarcyThomas
  • 1,218
  • 13
  • 30
Tyler Jensen
  • 811
  • 6
  • 12
1

You need Levenshtein Distance Algorithm for find how to go from one string to another by operations insert, delete and modify. You fuzzyMatchScoreThreshold is a Levenshtein Distance divided to length of the string in simple way.

Singlet
  • 317
  • 1
  • 4
  • 13