我确信我在Meta上看到过一篇文章,其中Jeff发布了升级后的算法,它更好地匹配了评论,例如,当有人输入评论时:
@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;
}
}
}
}
}发布于 2011-09-19 06:02:57
Peter Norvig在这里写了一个漂亮的very small spelling corrector例子:
它列出了两个C#实现。
对于您的特定问题(候选词集合非常小),您可能希望找到目标单词和所有候选词之间的最小edit distance。
https://stackoverflow.com/questions/7464676
复制相似问题