Speech-Trigger-Detection / replace_explitives.py
mskov's picture
Update replace_explitives.py
62b1c9a
raw
history blame
703 Bytes
import regex as re
def sub_explitives(textfile, selection):
replacetext = "person"
# text = word_tokenize(textfile)
# print(text)
# sentences = sent_tokenize(textfile)
if selection == "B-Word":
target_word = r"\bbitch\b"
elif selection == "N-Word":
target_word = r"\bnigga\b"
elif selection == "All Explitives":
target_word = r"\bshit\b"
else:
target_word = None
print("selection:", selection, "target_word:", target_word)
if target_word:
print("target word was found, ", target_word)
print(text)
textfile = re.sub(target_word, replacetext, textfile, flags=re.IGNORECASE)
return textfile