[英]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.