Profiles in the comments of Django

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?

+4
source share
2 answers

Django handles profanity filtering.

From https://docs.djangoproject.com/en/1.4/ref/settings/#profanities-list :

PROFANITIES_LIST

Default :() (empty tuple)

Corruption of profane people as lines that will be banned in comments when 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 .

+7
source

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. 
+2
source

Source: https://habr.com/ru/post/1434381/


All Articles