Skip to content

Instantly share code, notes, and snippets.

@vmarkovtsev
Last active February 20, 2021 10:54
Show Gist options
  • Save vmarkovtsev/f9291a712d7d3a4564c1bc878ab77a5a to your computer and use it in GitHub Desktop.
Save vmarkovtsev/f9291a712d7d3a4564c1bc878ab77a5a to your computer and use it in GitHub Desktop.
from fuzzywuzzy import fuzz
def distance_ratio(s1: str, s2: str) -> int:
return 100 - fuzz.ratio(s1, s2)
def distance_join_ratio(s1: str, s2: str) -> int:
return 100 - fuzz.ratio(s1.replace(" ", ""), s2.replace(" ", ""))
def distance_sort_ratio(s1: str, s2: str) -> int:
return 100 - fuzz.token_sort_ratio(s1, s2)
def distance_set_ratio(s1: str, s2: str) -> int:
return 100 - fuzz.token_set_ratio(s1, s2)
def distance_max_ratio(s1: str, s2: str) -> int:
return min(distance_set_ratio(s1, s2), distance_ratio_join(s1, s2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment