我想检查一下--用户=‘Jefferey Roberts',而fuzzywuzzy给出了这个结果-- result=('Jeremiah James Roberts Jr',86岁),(Jeffrey Scott Roberts,81岁),(Jeremiah J Roberts,71岁)
密码-
from fuzzywuzzy import process
user='Jefferey Roberts'
result=['Jeremiah James Roberts Jr', 'Jeffrey Scott Roberts', 'Jeremiah J Roberts']
output=process.extract(user,result)
print(output)它应该给结果列表中的第二个元素更多的分数。
类似地,如果我在这个列表“Gary”、“Zayn Waller”、“Debra”中搜索“Gary”,并搜索“Gary”,它将返回Zayn Waller,而不是Gary第一个索引。
密码-
from difflib import get_close_matches
user='Gary Waller'
result= ['Gary Wayne Waller', 'Zayn Waller', 'Debra Kay Waller']
output=get_close_matches(user,result)
print(output)请帮助解决任何解决方案或任何更好的准确模块,除了模糊和get_close_matches。
发布于 2022-10-01 11:19:44
你可以使用"SequenceMatcher“
from difflib import SequenceMatcher
b = "Jefferey Roberts"
a_lst = ['Jeremiah James Roberts Jr', 'Jeffrey Scott Roberts', 'Jeremiah J Roberts']
for a in a_lst:
print(a,SequenceMatcher(None, a, b).ratio())产出;
Jeremiah James Roberts Jr 0.5853658536585366
Jeffrey Scott Roberts 0.8108108108108109
Jeremiah J Roberts 0.7058823529411765编辑:
检查这个类似的匹配b/w字符串的文章,以查看所有可用于匹配的算法/包。Find the similarity metric between two strings
https://stackoverflow.com/questions/73917834
复制相似问题