Using Process.extract in fuzzywuzzy and the all max similar choices

浪子不回头ぞ 提交于 2021-01-28 21:55:45

问题


I have the following input-

query = 'Total replenishment lead time (in workdays)'
choices = ['PLANNING_TIME_FENCE_CODE', 'BUILD_IN_WIP_FLAG','Lead_time_planning', 'Total replenishment lead time 1', 'Total replenishment lead time  2']
print(process.extract(query, choices))

I get the following output-

[('Total replenishment lead time 1', 92), ('Total replenishment lead time  2', 92), ('Lead_time_planning', 50), ('PLANNING_TIME_FENCE_CODE', 36), ('BUILD_IN_WIP_FLAG', 26)]

But I just want all the best choices with a maximum similarity ratio even if the ratio is similar for two choices.

Please help.


回答1:


If I understand your question correct you would like to receive the following output:

[('Total replenishment lead time 1', 92), ('Total replenishment lead time  2', 92)]

You can achieve this by filtering the results of process.extract

matches = process.extract(query, choices, limit=None)
max_ratio = matches[0][1]
best_matches = []
for match in matches:
  if match[1] != max_ratio:
    break
  best_matches.append(match)


来源:https://stackoverflow.com/questions/65407585/using-process-extract-in-fuzzywuzzy-and-the-all-max-similar-choices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!