I want to loop through all fuzzy matching methods to determine which is the best for my data, from the package fuzzywuzzy.
Code:
from fuzzywuzzy import fuzz
# Discover ratio.
# This set should give a higher match than the set below.
high_match = ('AMERICAN SIGN LANG & ENG SECONDAR',
'47 The American Sign Language and English Secondary School')
low_match = ('AMERICAN SIGN LANG & ENG SECONDAR',
'The 47 American Sign Language & English Lower School')
method_list = [func for func in dir(fuzz) if callable(getattr(fuzz, func))]
for method in method_list:
high_ratio = fuzz.method(*high_match)
low_ratio = fuzz.method(*low_match)
def success(high_ratio, low_ratio):
if high_ratio > low_ratio:
return 'success'
else:
return 'failure'
print(f'The method {method} produced {success(high_ratio,low_ratio)}')
fuzz.method
is invalid.
I looked at other answers but didn't understand.