如何将特定人员模糊搜索到人员列表中(连接姓氏+姓氏)
How to fuzzy search for a specific person into a list of people (concatenated surname+lastname)
我正在尝试匹配这样的输入(来自第三方软件):
PIPPO CANASTA PER FT 501 del 1/11/2016
针对可以建模为字符串数组(来自另一个软件)的人员列表
[
...
"CANASTA PIPPO"
...
]
如何使用 C# (.NET) 完成此操作?
您可以将每个字符串拆分成一个单词数组,并在列表中搜索最多匹配元素的列表:
string[] arrayToSearch = new string[] {
"OTHER STUFF",
"CANASTA PIPPO",
"MORE STUFF"
};
string stringToFind = "PIPPO CANASTA PER FT 501 del 1/11/2016";
string[] wordsToFind = stringToFind.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries);
string bestMatch = arrayToSearch.OrderByDescending(
s => s.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries)
.Intersect(wordsToFind, StringComparer.OrdinalIgnoreCase)
.Count()
).FirstOrDefault();
Console.WriteLine("Best match: " + bestMatch);
Console.ReadKey();
我正在尝试匹配这样的输入(来自第三方软件):
PIPPO CANASTA PER FT 501 del 1/11/2016
针对可以建模为字符串数组(来自另一个软件)的人员列表
[
...
"CANASTA PIPPO"
...
]
如何使用 C# (.NET) 完成此操作?
您可以将每个字符串拆分成一个单词数组,并在列表中搜索最多匹配元素的列表:
string[] arrayToSearch = new string[] {
"OTHER STUFF",
"CANASTA PIPPO",
"MORE STUFF"
};
string stringToFind = "PIPPO CANASTA PER FT 501 del 1/11/2016";
string[] wordsToFind = stringToFind.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries);
string bestMatch = arrayToSearch.OrderByDescending(
s => s.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries)
.Intersect(wordsToFind, StringComparer.OrdinalIgnoreCase)
.Count()
).FirstOrDefault();
Console.WriteLine("Best match: " + bestMatch);
Console.ReadKey();