Meta または SO で、たとえば誰かがコメントを入力したときなど、コメントをより適切に照合するアップグレードされたアルゴリズムを 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# であるため、その言語の例があれば素晴らしいでしょう。これは私がこれまでに持っているもので、EXACT マッチ (すべて小文字) に最適です。
// 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;
}
}
}
}
}