diff --git a/profanityfilter/profanityfilter.py b/profanityfilter/profanityfilter.py index 497e473..6230318 100644 --- a/profanityfilter/profanityfilter.py +++ b/profanityfilter/profanityfilter.py @@ -1,6 +1,6 @@ import os import re - +import string import inflection @@ -66,7 +66,15 @@ def set_censor(self, character): def has_bad_word(self, text): """Returns True if text contains profanity, False otherwise.""" - return self.censor(text) != text + prof = {} + for word in self.get_profane_words(): + prof[word.lower()] = True + for word in text.split(): + lower = word.lower() + without_punc = ''.join(ch for ch in lower if ch not in set(string.punctuation)) + if prof.get(lower, False) or prof.get(without_punc, False): + return True + return False def get_custom_censor_list(self): """Returns the list of custom profane words."""