Since Django does not handle filtering profanity, does anyone have any suggestions on how to easily implement some natural language processing / filtering profanity in django?
Django handles profanity filtering.
From https://docs.djangoproject.com/en/1.4/ref/settings/#profanities-list :
PROFANITIES_LISTDefault :() (empty tuple)Corruption of profane people as lines that will be banned in comments when COMMENTS_ALLOW_PROFANITIES False .
PROFANITIES_LIST
Default :() (empty tuple)
Corruption of profane people as lines that will be banned in comments when COMMENTS_ALLOW_PROFANITIES False .
COMMENTS_ALLOW_PROFANITIES
False
However, you will need to fill out this list. Some links to get started .
I also got acquainted with the Scunthorpe problem .
Personally, I say ... do not worry. If you create better filters, they will just enter it differently ...
But here is a simple example:
import re bad_words = ['spam', 'eggs'] # The \b gives a word boundary so you don't have the Scunthorpe problem: http://en.wikipedia.org/wiki/Scunthorpe_problem pattern = re.compile( r'\b(%s)\b' % '|'.join(bad_words), re.IGNORECASE, ) some_text = 'This text contains some profane words like spam and eggs. But it wont match spammy stuff.' print some_text # This text contains some profane words like spam and eggs. But it wont match spammy stuff. clean_text = pattern.sub('XXX', some_text) print clean_text # This text contains some profane words like XXX and XXX. But it wont match spammy stuff.
Source: https://habr.com/ru/post/1434381/More articles:https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1434376/is-it-a-good-practice-to-convert-all-non-ssl-references-to-ssl-in-a-php-page-by-strreplacing-the-content-in-output-buffer&usg=ALkJrhiYc3ir2rPHsGSItn53fXR6N9feAQSaving plot in octave with transparent background - octaveThread.CurrentThread.CurrentCulture and ajax - ajaxusing json webservice on windows phone 7 - jsonHow to save hasMany association in one Ember.js form using Ember Data & Rails? - ruby-on-railsusing emberjs didInsertElement to display two separate calendars or two instances of a jquery fullcalendar plugin object - jqueryC ++ The main loop of abstraction - c ++MBProgressHud and SDWebImagePrefetcher - iosEmberjs - unable to request an embedded model or association - ember.jsList of all Android devices with features - androidAll Articles