【问题标题】:Fuzzywuzzy is not giving proper resultFuzzywuzzy 没有给出正确的结果
【发布时间】:2022-10-01 19:19:44
【问题描述】:

我想检查一下 - 用户=\'杰弗里罗伯茨\' 并且fuzzywuzzy给出了这个结果- 结果=[(\'Jeremiah James Roberts Jr\', 86), (\'Jeffrey Scott Roberts\', 81), (\'Jeremiah J Roberts\', 71)]

它应该给结果列表的第二个元素更多的分数。 请帮助解决除fuzzywuzzy和get_close_matches之外的任何解决方案或任何更准确的模块

  • 您能否提供支持代码以便我们重现问题?

标签: python


【解决方案1】:

您可以使用“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

【讨论】:

    猜你喜欢
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    • 2012-08-30
    • 2016-04-15
    相关资源
    最近更新 更多