1

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.

thepunitsingh
  • 713
  • 1
  • 12
  • 30

2 Answers2

0

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)
maxbachmann
  • 2,862
  • 1
  • 11
  • 35
0

There is a function included in the fuzzywuzzy library which is called extractBests. I would suggest as following:

best_score = process.extractOne(query, choices)[1] #gets the score of the best match
matches = process.extractBests(query, choices, score_cutoff=best_score) #returns list with equally goot matches (tuples with match and ratio)