gpt4 book ai didi

python - FuzzyWuzzy 提取物中的奇怪行为

转载 作者:行者123 更新时间:2023-12-01 01:53:37 24 4
gpt4 key购买 nike

我正在尝试使用 FuzzyWuzzy 来纠正文本中拼写错误的名称。但是,我无法让 process.extract 和 process.extractOne 按照我预期的方式运行。

from fuzzywuzzy import process

the_text = 'VICTOR HUGO e MARIANA VEIGA'
search_term = 'VEYGA'

the_text = the_text.split()
found_word = process.extract(search_term, the_text)

print(found_word)

这会导致:

[('e', 90), ('VEIGA', 80), ('HUGO', 22), ('VICTOR', 18), ('MARIANA', 17)]

如何让 FuzzyWuzzy 正确识别“VEIGA”作为正确的响应?

最佳答案

您可以尝试使用:fuzz.token_set_ratio 或 fuzz.token_sort_ratio答案在这里:When to use which fuzz function to compare 2 strings给出了很好的解释。

这里有一些代码:

from fuzzywuzzy import process
from fuzzywuzzy import fuzz

the_text = 'VICTOR HUGO e MARIANA VEIGA'
search_term = 'VEYGA'

the_text = the_text.split()
found_word = process.extract(search_term, the_text, scorer=fuzz.token_sort_ratio)

print(found_word)

输出:

[('VEIGA', 80), ('e', 33), ('HUGO', 22), ('VICTOR', 18), ('MARIANA', 17)]

关于python - FuzzyWuzzy 提取物中的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50468250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com