fuzzywuzzy icon indicating copy to clipboard operation
fuzzywuzzy copied to clipboard

Disguised letter combinations

Open tjhutton87 opened this issue 5 years ago • 1 comments

Would it be possible to include an optional parameter to check each letter of a searched string against a disguised letter dictionary including combinations such as "rn" ("r" and "n") being substituted for "m"?

For example, I want to search for the word "meal", but I want to include results that match "rneal".

Possible disguised letter combinations include but aren't limited to:

'l'o' = b 'o'l' = d 'r'n' = m 'r'i' = n 'n'n' = m 'v'v' = w

tjhutton87 avatar Jan 15 '20 14:01 tjhutton87

Hm my personal approach towards this problem would be to use something like the following:

def disguised_letter_fix(s):
    replacements = {
        'vv': 'w',
        'nn': 'm'
    }
    pattern = re.compile(r'(' + '|'.join(replacements.keys()) + r')')
    result = pattern.sub(lambda x: replacements[x.group()], s)
    return fuzzywuzzy.utils.default_process(s)

fuzzywuzzy.process.extractOne(a, b, processor=disguised_letter_fix)

maxbachmann avatar Mar 27 '20 15:03 maxbachmann