I want to show you useful python library to string matching. It’s very easy to use.
FuzzyWuzzy is the python library to matching string.
[shell]
pip install fuzzywuzzy
[/shell]
And short example how to use it:
[python]
from difflib import SequenceMatcher
m = SequenceMatcher(None, “My test string”, “My test string”)
print(“Match ratio for ‘My test string’ and ‘My test string’ is “, m.ratio())
m = SequenceMatcher(None, “My test string”, “My test string string”)
print(“Match ratio for ‘My test string’ and ‘My test string string’ is “, m.ratio())
m = SequenceMatcher(None, “My test string”, “Something completely different”)
print(“Match ratio for ‘My test string’ and ‘Something completely different’ is “, m.ratio())
m = SequenceMatcher(None, “My test string”, “My different string”)
print(“Match ratio for ‘My test string’ and ‘My different string’ is “, m.ratio())
m = SequenceMatcher(None, “My test string”, “”)
print(“Match ratio for ‘My test string’ and empty string is “, m.ratio())
[/python]
And the result:
Match ratio for 'My test string' and 'My test string' is 1.0< Match ratio for 'My test string' and 'My test string string' is 0.8 Match ratio for 'My test string' and 'Something completely different' is 0.18181818181818182 Match ratio for 'My test string' and 'My different string' is 0.7272727272727273 Match ratio for 'My test string' and empty string is 0.0