What is a simple fuzzy string matching algorithm in Python?

前端 未结 7 907
不知归路
不知归路 2020-12-13 00:55

I\'m trying to find some sort of a good, fuzzy string matching algorithm. Direct matching doesn\'t work for me — this isn\'t too good because unless my strings are a 100% si

7条回答
  •  醉话见心
    2020-12-13 01:30

    If all you want to do is to test whether or not all the words in a string match another string, that's a one liner:

    if not [word for word in b.split(' ') if word not in a.split(' ')]:
        print 'Match!'
    

    If you want to score them instead of a binary test, why not just do something like:

    ((# of matching words) / (# of words in bigger string)) * ((# of words in smaller string) / (# of words in bigger string))

    ?

    If you wanted to, you could get fancier and do fuzzy match on each string.

提交回复
热议问题