Snippet List
Simple Python snippet to detect if any word in a list of words is inside your string. Use for profanity checking (my use case), auto tag detection, scoring, etc.
This will return an empty list if the word is not in the list. Assumes everything in words_to_find is lower case. Can probably be done cleaner with regular expressions but this method is extremely readable for those that prefer none regex solutions.
A better way of dealing w/profanity - disemvowel it!
From [Wikipedia](http://en.wikipedia.org/wiki/Disemvoweling), "disemvoweling is a technique used to censor unwanted postings such as spam, internet trolling, rudeness or criticism and yet maintain some transparency, both of the act and the underlying word." Credit: Boing Boing
Example:
This original sentence:
In the fields of Internet discussion and forum moderation, disemvoweling (also spelled disemvowelling) is the removal of vowels from text.
would be disemvowelled to look like this:
n th flds f ntrnt dscssn nd frm mdrtn, dsmvwlng (ls splld dsmvwllng) s th rmvl f vwls frm txt.
Usage:
body_input = form.cleaned_data["body"]
body_input = disemvowel_profanity(body_input)
I wanted a global way to filter profanity w/out having to modify every model, view, or form. While middleware takes overhead, this technique is intended mainly for sites w/few postbacks. Hopefully this snippet will lead to more/better techniques in the comments below.
Usage (settings.py):
MIDDLEWARE_CLASSES = (
'PROJECT_NAME.FILE_NAME.ProfanityFilterMiddleware',
)
4 snippets posted so far.