【发布时间】:2011-01-26 23:23:33
【问题描述】:
我目前正在从事一个需要实施数据匹配算法的项目。 外部系统传入它所知道的有关客户的所有数据,而我设计的系统必须返回匹配的客户。因此,外部系统随后会知道客户的正确 id,并且它会获取额外的数据,或者可以更新自己的特定客户的数据。
传入以下字段:
- 姓名
- 姓名2
- 街道
- 城市
- 邮政编码
- 银行账户号码
- 银行名称
- 银行代码
- 电子邮件
- 电话
- 传真
- 网络
数据可以是高质量的,并且有很多信息可用,但通常数据很糟糕,只有名称和地址可用,并且可能有拼写。
我正在.Net 中实施该项目。我目前做的事情是这样的:
public bool IsMatch(Customer customer)
{
// CanIdentify just checks if the info is provided and has a specific length (e.g. > 1)
if (CanIdentifyByStreet() && CanIdentifyByBankAccountNumber())
{
// some parsing of strings done before (substring, etc.)
if(Street == customer.Street && AccountNumber == customer.BankAccountNumber) return true;
}
if (CanIdentifyByStreet() && CanIdentifyByZipCode() &&CanIdentifyByName())
{
...
}
}
我对上述方法不太满意。这是因为我必须为所有合理的情况(组合)编写 if 语句,所以我不会错过任何匹配实体的机会。
所以我想也许我可以创建某种匹配的分数。因此,对于每个匹配的标准,都会添加一个分数。喜欢:
public bool IsMatch(Customer customer)
{
int matchingScore = 0;
if (CanIdentifyByStreet())
{
if(....)
matchingScore += 10;
}
if (CanIdentifyByName())
{
if(....)
matchingScore += 10;
}
if (CanIdentifyBankAccountNumber())
{
if(....)
matchingScore += 10;
}
if(matchingScore > iDontKnow)
return true;
}
这将允许我考虑所有匹配数据,并根据某些权重增加匹配分数。如果分数足够高,那就是匹配。
知道我的问题是:是否有针对此类事情的最佳实践,例如匹配算法模式等?非常感谢!
【问题讨论】:
-
你的意思是“拼写错误”,对吧?
标签: .net algorithm design-patterns