Final try to make it all work

This commit is contained in:
Yo Mama 2021-10-20 01:32:28 +02:00
parent 6a350e8242
commit d83a97e864
2 changed files with 17 additions and 11 deletions

View file

@ -41,9 +41,9 @@ def get_permutations_slur(slur: str, replacer: str = "_") -> Dict[str, str]:
def create_slur_regex() -> Pattern[str]:
"""Creates the regex that will find the slurs"""
single_words = "|".join([slur.strip().lower() for slur in SLURS.keys()])
single_words = "|".join([slur.lower() for slur in SLURS.keys()])
return re.compile(rf"(?i)(?<=\s|>)({single_words})(?=[\s<,.])")
return re.compile(rf"(?i)(?<=\s|>)({single_words})([\s<,.])")
def create_replace_map() -> Dict[str, str]:
@ -60,9 +60,9 @@ REPLACE_MAP = create_replace_map()
def sub_matcher(match: Match) -> str:
"""given a match returns the correct replacer string"""
found = match.group(0)
found = match.group(1)
# if it does not find the correct capitalization, it tries the all lower, or return the original word
return REPLACE_MAP.get(found) or REPLACE_MAP.get(found.lower()) or found
return (REPLACE_MAP.get(found) or REPLACE_MAP.get(found.lower()) or found) + match.group(2)
def censor_slurs(body: str, logged_user) -> str: