Last active
February 18, 2021 16:34
-
-
Save vmarkovtsev/f690231f3e6ef147b831c567b0c1c61e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from metaphone import doublemetaphone | |
from unidecode import unidecode | |
nonalphanumeric_re = re.compile(r"[^\w ]+") | |
whitespace_re = re.compile(r" +") | |
def normalize_simple(name: str) -> str: | |
return whitespace_re.sub(" ", nonalphanumeric_re.sub(" ", name.lower())) | |
def normalize_unidecode(name: str) -> str: | |
return normalize_simple(unidecode(name)) | |
def normalize_unidecode_metaphone(name: str) -> str: | |
return " ".join(doublemetaphone(part)[0] | |
for part in normalize_unidecode(name).split(" ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment