9

我需要实现某种这样的:

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.
}

这是用 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;
}

但我不知道如何在 IsFuzzyMatch 方法中实现逻辑。有任何想法吗?也许为此目的有现成的解决方案?

4

2 回答 2

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.

于 2011-05-28T01:37:43.330 回答
1

您需要Levenshtein 距离算法来查找如何通过插入、删除和修改操作从一个字符串转到另一个字符串。您fuzzyMatchScoreThreshold 是一个Levenshtein 距离,以简单的方式除以字符串的长度。

于 2010-11-03T11:16:34.600 回答