Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions profanityfilter/profanityfilter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import re

import string
import inflection


Expand Down Expand Up @@ -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."""
Expand Down