算法寻找模糊@username
问题描述:
用户匹配我敢肯定,我看到了一元后或SO杰夫发布升级后的算法一致意见更好,例如当某人类型评论:算法寻找模糊@username
@Tom did you see
它将匹配用户名'Tom'。如果有特殊字符,比如我的用户名是'T0m',并且有人输入@Tom
,那么它仍然匹配。
有没有人有链接到这个职位,如果它确实存在?如果我没有记错,那是他分享的代码,并且对我有用!
否则,给谁参与讨论的用户名列表:
users[0] = "Tom"
users[1] = "Peanut"
users[2] = "Ashley"
users[3] = "Jon"
users[4] = "AARÓN"
而且您将得到@Aaron
或@Aron
作为输入,什么是选择正确的用户的最佳方式,在被称为清单?
一个通用的算法会很好,但我正在做的网站是ASP.net c#所以如果有一个在该语言的例子,它将是辉煌的。这是我到目前为止,它的伟大工程的完全匹配(全部小写):
// Find comment references
if (Search.Type != Alerts.SectionType.error)
{
// A list of all lower case usernames refered to in this thread
string[] References = Alerts.CommonFunctions.extractReferences(Comment);
// Only proceed if any references are found
if (References.Count() > 0)
{
// Extract all usernames involved in this comment discussion
UserBasic[] UsernamesInThread = getAllUsernamesInThread(Anchor);
// Loop each reference
foreach (string r in References)
{
// Try to find a match
foreach (UserBasic u in UsernamesInThread)
{
// Exact match found
if (r == u.Username)
{
// Check it's not original author (we can then ignore as alert already issued)
if (u.UserID != Search.OriginalAuthorID)
{
Alerts.CommonFunctions.createAlert(u.UserID, Settings.CommentReplyAlertID, Search.URL, Search.Title);
}
break;
}
}
}
}
}
答
彼得·诺维格写了very small spelling corrector这里的美丽的例子:
它有两个C#实现上市。
对于您的特定问题(候选人集合非常小),您可能希望在目标单词和所有候选人之间找到最小的edit distance。
也许这? http://en.wikipedia.org/wiki/Levenshtein_distance –
不要忘记字母间距 - e应该比r大l。 – apscience