Giter Site home page Giter Site logo

wordfilter's Introduction

wordfilter

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

Getting Started

Install the module with: npm install wordfilter

var wordfilter = require('wordfilter');
wordfilter.blacklisted('does this string have a bad word in it?'); // "false"

// clear the list entirely
wordfilter.clearList();

// add new words
wordfilter.addWords(['zebra','elephant']);
wordfilter.blacklisted('this string has zebra in it'); // "true"

// remove a word
wordfilter.removeWord('zebra');
wordfilter.blacklisted('this string has zebra in it'); // "false"

Or with Python: Install the module with: pip install wordfilter

from wordfilter import Wordfilter
wordfilter = Wordfilter()
wordfilter.blacklisted('does this string have a bad word in it?')  # False

# clear the list entirely
wordfilter.clearList()

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

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.

wordfilter's People

Contributors

averykatko avatar brainwane avatar dariusk avatar elib avatar fluffy-critter avatar foozmeat avatar hugovk avatar jamespanic avatar jimkang avatar mambocab avatar matthewmcvickar avatar maxiboch avatar moonmilk avatar mrflynn avatar puckey avatar rdlester avatar suisea avatar techdubb avatar tinruufu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wordfilter's Issues

Filter to aggressive.

Hello not sure if this is a use case for the project. I have written test.

'good word containing blacklist word': function(test) {
wordfilter.clearList();
wordfilter.addWords(['wop']);
test.equal(wordfilter.blacklisted('Swopped'), false, 'good word contain blacklist word shouldnt fail');
test.done();
}

Antiquated forms

The word “gyp” is rightfully in the list. I recently discovered that there’s an alternate spelling, “gip,” that should be added as well, as this spelling appears in many bot wordlists and usually evades slur detection.

Errors importing from PyPi on Python 3.6

When running an import command on Python 3.6:

from wordfilter import Wordfilter

I get the following error message:

/path/to/python3.6/site-packages/wordfilter/wordfilter.py in __init__(self, blacklist, datafile)
     27         else:
     28             data = resource_string('wordfilter', '../badwords.json').decode('utf-8')
---> 29             self.blacklist = [s.lower() for s in json.loads(data, 'r')]
     30
     31     def blacklisted(self, string):

TypeError: loads() takes 1 positional argument but 2 were given

I was able to successfully import the package by removing the second argument, but then none of the methods except for blacklisted() seemed to load:

In [1]: from wordfilter import Wordfilter

In [2]: filt = Wordfilter()

In [3]: filt.blacklisted('bitch')
Out[3]: True

In [4]: filt.removeWord('bitch')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-03c22b14e163> in <module>()
----> 1 filt.removeWord('bitch')

AttributeError: 'Wordfilter' object has no attribute 'removeWord'

This may be expected behavior, but I figured I'd file an issue just in case! I'm on OS X, if that helps at all. I was also able to get around this issue by twiddling things on my end, so this is not a high-priority issue.

F word

Is it missing from badwords.json?

New Python release

Hi @fitnr,

The latest release on PyPI (and the one you get from pip install wordfilter) is 0.2.5.

The Python source hasn't changed, but badwords.json has and it's at 0.2.6.

Please could you make a new Python release? I think it probably makes sense to merge your setup.py into this repo too.

Thanks!

Minor wording change!

Hey Darius!

Always loved this repos, but as I was revisiting it for a new bot, I had the realization that if you were to make this today, you'd probably do a few minor things differently with naming, eg using banlisted instead of blacklisted.

No sweat if you are too busy with other stuff or if this would cause a whole bunch of problems for people with code in the wild, just thought I'd leave it as a note!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.