使用Python Dedupe库设置用于匹配记录的显式规则

bla*_*lah 2 python duplicates record-linkage python-dedupe

我正在使用Dedupe库将人员记录彼此匹配。我的数据包括姓名,出生日期,地址,电话号码和其他个人身份信息。

这是我的问题:例如,如果两个记录具有匹配的名称和电话号码,我总是希望100%置信度匹配它们。

这是我的一些代码示例:

fields = [
    {'field' : 'LAST_NM', 'variable name' : 'last_nm', 'type': 'String'},
    {'field' : 'FRST_NM', 'variable name' : 'frst_nm', 'type': 'String'},
    {'field' : 'FULL_NM', 'variable name' : 'full_nm', 'type': 'Name'},
    {'field' : 'BRTH_DT', 'variable name' : 'brth_dt', 'type': 'String'},
    {'field' : 'SEX_CD', 'type': 'Exact'},
    {'field' : 'FULL_US_ADDRESS', 'variable name' : 'us_address', 'type': 'Address'},
    {'field' : 'APT_NUM', 'type': 'Exact'},
    {'field' : 'CITY', 'type': 'ShortString'},
    {'field' : 'STATE', 'type': 'ShortString'},
    {'field' : 'ZIP_CD', 'type': 'ShortString'},
    {'field' : 'HOME_PHONE', 'variable name' : 'home_phone', 'type': 'Exact'},
    {'type': 'Interaction', 'interaction variables' : ['full_nm', 'home_phone']},
Run Code Online (Sandbox Code Playgroud)

在重复数据删除库中,有什么方法可以让我明确匹配两个或多个字段?根据文档,“一个交互字段将多个变量的值相乘。” (https://dedupe.readthedocs.org/en/latest/Variable-definition.html#interaction)。我想执行一个严格的规则,使其与100%的置信度相匹配-不仅仅是将变量的值相乘。我问的原因是,我发现Dedupe偶尔会错过这两个条件下的某些比赛(可能是由于我训练时间不够长,但无论如何,我只想将这些比赛硬编码到脚本中)。

有什么建议么?

fgr*_*egg 5

Dedupe没有此功能,而且可能永远也不会(我是主要作者之一)。如果确实是在这些字段上完全匹配意味着记录是共同引用的规则,则可以在将其余记录发送到Dedupe之前编写一些代码以明确匹配这些代码。

exact_matches = defaultdict(list)
for record_id, record in records.items():
    match_key = (record['name'], record['phone'])
    exact_matches[match_key].append(record_id)

partially_deduplicated = []
exact_lookup = {}
for match_group in exact_matches.values():
     head_id = match_group.pop()
     partially_deduplicated.append((head_id, records[head_id]))
     for dupe_id in match_group :
         exact_lookup[dupe_id] = head_id
Run Code Online (Sandbox Code Playgroud)