[英]Alternative approach to using agrep() for fuzzy matching in R
我有一个大的行政数据文件,大约 100 万条记录。 在这个数据集中,个人可以多次表示。 大约一半的记录具有将记录映射到个人的识别代码; 对于没有的那一半,我需要模糊匹配名称以标记可能属于同一个人的记录。
通过查看带有识别码的记录,我创建了一个在同一个人的姓名记录中出现的差异列表:
鉴于我所追求的匹配类型,有没有比使用 agrep()/levenshtein 的距离更好的方法,这在 R 中很容易实现?
编辑:R 中的 agrep() 不能很好地解决这个问题 - 因为我需要允许大量的插入和替换来解释名称记录方式的不同,所以会抛出很多错误的匹配项.
我会多次传球。
"Jon .* Snow"
- 中间名
"Jon .*Snow"
- 第二个姓氏
昵称需要一个从长到短的映射字典,没有正则表达式可以处理他的。
"Snow Jon"
——逆转(duh)
agrep 将处理轻微的拼写错误。
您可能还想将您的名字标记为名字、中间和姓氏。
合成器包( https://cran.r-project.org/web/packages/synthesisr/index.html )可能会有所帮助。 它使用 R 代码来模仿fuzzywuzzy Python 包和fuzzywuzzyR 中的一些模糊匹配功能。 从fuzzywuzzy 中获取了类似的不同指标; 较低的分数意味着更大的相似性。 这些方法可以通过不同的方式访问,如下所示。
具体来说,在这种情况下,“标记”函数可能很有用,因为字符串由空格标记,然后按字母顺序排列以处理反转等情况。
library(synthesisr)
fuzz_m_ratio("this is a test", "this is a test!")
fuzzdist("this is a test", "this is a test!", method = "fuzz_m_ratio")
fuzz_partial_ratio("this is a test", "this is a test!")
fuzzdist("this is a test", "this is a test!", method = "fuzz_partial_ratio")
fuzz_token_sort_ratio("this is a test", "this is a test!")
fuzzdist("this is a test", "this is a test!", method = "fuzz_token_sort_ratio")
fuzz_token_set_ratio("this is a test", "this is a test!")
fuzzdist("this is a test", "this is a test!", method = "fuzz_token_set_ratio")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.