Skip to main content

A small module meant for use in text generators that lets you filter strings for bad words.

Project description

A small module meant for use in text generators that lets you filter strings for bad words.

Getting Started

Install the module with pip install wordfilter

> import wordfilter
> wordfilter.blacklisted("does this string have a bad word in it?")
False

# add new words
> wordfilter.add_words(["zebra", "elephant"])
> wordfilter.blacklisted("this string has zebra in it")
True

# remove a word
> wordfilter.remove_words('zebra')
> wordfilter.blacklisted('this string has zebra in it')
False

# clear the list entirely
> wordfilter.clear_list()

Documentation

This is a word filter adapted from code that I use in a lot of my twitter bots. It is based on a list of words that I’ve hand-picked for exclusion from my bots: essentially, it’s a list of things that I would not say myself. Generally speaking, they are “words of oppression”, aka racist/sexist/ableist things that I would not say.

The list is not all-inclusive, and I’m always adding words to it. If you’d like to file an issue or a pull request to add more words, please do so, but understand that this is primarily for use in my own projects, and I may not agree to add certain words. (For example, I have no problem with scatological words, so “shit” and “fuck” will never be on this list.)

Words are case insensitive.

Also note that due to the complexities of the English language, I am considering anything containing the substring of a bad word to be blacklisted. For example, even though “homogenous” is not a bad word, it contains the substring “homo” and it gets filtered. The reason for this is that new slang pops up all the time using compound words and I can’t possibly keep up with it. I’m willing to lose a few words like “homogenous” and “Pakistan” in order to avoid false negatives.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

Copyright (c) 2013 Darius Kazemi
Licensed under the MIT license.

Project details


Release history Release notifications

This version
History Node

0.2.6.2

History Node

0.2.6.1

History Node

0.2.6

History Node

0.2.5

History Node

0.1.9

History Node

0.1.8

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
wordfilter-0.2.6.2-py2.py3-none-any.whl (5.7 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Mar 20, 2017
wordfilter-0.2.6.2.tar.gz (3.5 kB) Copy SHA256 hash SHA256 Source None Mar 20, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page