【问题标题】:Need Algorithm for finding Highest match when comparing a list of strings比较字符串列表时需要算法来查找最高匹配
【发布时间】:2013-12-01 03:10:29
【问题描述】:

我有一个从 Excel 表中导入列的函数,然后我将列名放入列表中。

我有一个“系统列”列表,导入的列最终将与之映射。

用户稍后将能够将这些列映射到任何系统列,但我希望通过智能地尝试将导入的列名称与最接近它的系统列名称进行匹配来简化此过程。

例如

导入他们的列后,我可能有以下导入列的列表:

List<string> importedColumnNames = importService.ResolveColumnNames();

Console.WriteLine(importedColumnNames[0]); //Prints 'Security_ID'
Console.WriteLine(importedColumnNames[1]); //Prints 'User_ID'
Console.WriteLine(importedColumnNames[2]); //Prints 'Date'

*注意*写入控制台的代码只是为了显示一些示例导入的列名。

此外,系统列名称的代码可能如下:

List<string> systemColumnNames = GetSystemColumnNames();

Console.WriteLine(systemColumnNames[0]); //Prints 'Security Identifier' or 'Security ID'
Console.WriteLine(systemColumnNames[1]); //Prints 'User' or 'User Identifier'
Console.WriteLine(systemColumnNames[2]); //Prints 'Item Date' or 'Datetime'

一旦这些被导入,我希望能够找到一种方法将导入的ColumnNames 与最接近的匹配系统列名值匹配。

Dictionary<string,string> matchedImportedColumns = MatchService.Match(importedColumnNames,systemColumnNames);

foreach(var item in matchedImportedColumns)
{
   Console.WriteLine("Imported Value '{0}' was matched to System Value '{1}',item.Key,item.Value);
} 

这有望打印出如下内容:

Imported Value 'Security ID' was matched to System Value 'Security Identifier'
Imported Value 'User ID' was matched to System Value 'User'
Imported Value 'Date' was matched to System Value 'Item Date'

还有一点需要注意的是,我希望对此有一个问题是是否使其区分大小写。我希望这可能是我可以在运行时做的事情,只需传入一个是否区分大小写进行匹配的布尔标志。

提前谢谢。

【问题讨论】:

  • 有人愿意告诉我为什么这被否决了吗?

标签: c# regex algorithm pattern-matching string-matching


【解决方案1】:

我想对于您的情况,最简单的方法(例如,最好不要破坏机器学习)是将它们分成单词(在空格和下划线上,可能是从小写到大写的转换),小写他们,找到查询和每个候选之间的集合交集的大小,并返回具有最大交集的候选。您可以通过执行您观察到的常见替换来改进它,例如“ID”->“标识符”(在查询和候选集上)。

如果您需要进行单射的集合到集合的匹配,那么您需要进行一些动态规划来找到最佳的非冲突匹配集合,而不是仅仅按顺序进行并将最佳匹配映射到每个集合。

【讨论】:

    猜你喜欢
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 2018-08-03
    相关资源
    最近更新 更多