Algorithm 在fuzzy@username上查找用户匹配项的算法
我肯定我在Meta上看到过一篇帖子,Jeff发布了升级后的算法,该算法能更好地匹配评论,例如,当有人键入评论时:Algorithm 在fuzzy@username上查找用户匹配项的算法,algorithm,comments,fuzzy-search,Algorithm,Comments,Fuzzy Search,我肯定我在Meta上看到过一篇帖子,Jeff发布了升级后的算法,该算法能更好地匹配评论,例如,当有人键入评论时: @Tom did you see 它将匹配用户名“Tom”。如果有特殊字符,就说我的用户名是“T0m”,有人键入@Tom它仍然匹配 如果这个帖子确实存在的话,有没有人可以链接到它?如果我没记错的话,这是他共享的代码,对我来说很有用 否则,给出参与讨论的用户名列表: users[0] = "Tom" users[1] = "Peanut" users[2] = "Ashley" us
@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#,所以如果有这种语言的例子的话,那就太棒了。这就是我到目前为止所做的,它非常适合精确匹配(全部小写):
彼得·诺维格在这里写了一个很好的例子: 它列出了两个C#实现
对于您的特定问题(候选词集非常小),您可能希望找到目标词和所有候选词之间的最小值。也许是这样?别忘了字母间距-e应该比l更匹配r。
// 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;
}
}
}
}
}