2
用戶匹配我敢肯定,我看到了一元后或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;
}
}
}
}
}
也許這? http://en.wikipedia.org/wiki/Levenshtein_distance –
不要忘記字母間距 - e應該比r大l。 – apscience