Like https://stackoverflow.com/questions/1521646/best-profanity-filter, but for Python — and I’m looking for libraries I can run and control myself locally, as opposed to web services.
(And whilst it’s always great to hear your fundamental objections of principle to profanity filtering, I’m not specifically looking for them here. I know profanity filtering can’t pick up every hurtful thing being said. I know swearing, in the grand scheme of things, isn’t a particularly big issue. I know you need some human input to deal with issues of content. I’d just like to find a good library, and see what use I can make of it.)
I didn't found any Python profanity library, so I made one myself.
Parameters
filterlist
A list of regular expressions that match a forbidden word. Please do not use
\b
, it will be inserted depending oninside_words
.Example:
['bad', 'un\w+']
ignore_case
Default:
True
Self-explanatory.
replacements
Default:
"$@%-?!"
A string with characters from which the replacements strings will be randomly generated.
Examples:
"%&$?!"
or"-"
etc.complete
Default:
True
Controls if the entire string will be replaced or if the first and last chars will be kept.
inside_words
Default:
False
Controls if words are searched inside other words too. Disabling this
Module source
(examples at the end)