Forum: Ruby on Rails Profanity Filter for Rails Application

55d6457963d5be7ad341343105ddc8a3?d=identicon&s=25 Nathan Esquenazi (xgamerx)
on 2007-09-05 12:51
I am creating an application that allows a user to post messages to a
board. I want to be able to filter profanity. For instance if someone
types an inappropriate word of 5 characters I want it to read "#?@#@" or
whatever. Ideally, I would be able to install a rails plugin or ruby gem
and then simply write


Code :   - fold - unfold

  --> message_text.hide_profanity! <--

and that would automatically hide all words deemed inappropriate by the
filter.

I would also be OK with it being part of the validation, i.e.

 --> validates_no_profanity :message <--

which would raise errors should there be any profanity in the value.

Is there any easy rails plugin or ruby gem that does this. This seems
like such a common need for an application that reinventing the wheel
seems foolish.

Thanks,

-Nathan
E3513c4edd6810bb4b9914b58da2a2c3?d=identicon&s=25 Jamal Soueidan (jamal)
on 2007-09-05 13:43
Can't you use the original text and the message_text.hide_profanity!
text and combine them together?
Bd2d12f85f54f93d3c9e2f558a593024?d=identicon&s=25 Mark Thomas (markthomas)
on 2007-09-05 18:05
(Received via mailing list)
I haven't seen any but it wouldn't be that hard to RYO with word
lists. Also, you can check out www.webpurify.com which is a service
with a REST API (free for non-commercial use).

If you were to RYO, you may want to think about the following:
- converting L337-speak to letters prior to filtering (e.g. @ -> a, |
\| -> n)
- using wordlists for multiple languages
96630febb655a1425f1279cc68c1dfa2?d=identicon&s=25 Adam Bair (adambair)
on 2008-06-01 05:01
Nathan Esquenazi wrote:
> I am creating an application that allows a user to post messages to a
> board. I want to be able to filter profanity. For instance if someone
> types an inappropriate word of 5 characters I want it to read "#?@#@" or
> whatever. Ideally, I would be able to install a rails plugin or ruby gem
> and then simply write
>
>
> Code :   - fold - unfold
>
>   --> message_text.hide_profanity! <--
>
> and that would automatically hide all words deemed inappropriate by the
> filter.
>
> I would also be OK with it being part of the validation, i.e.
>
>  --> validates_no_profanity :message <--
>
> which would raise errors should there be any profanity in the value.
>
> Is there any easy rails plugin or ruby gem that does this. This seems
> like such a common need for an application that reinventing the wheel
> seems foolish.
>
> Thanks,
>
> -Nathan

I just created a Profanity Filter plugin for Rails during the Community
Code Drive at RailsConf 08.  It's just a one-liner in your model.  You
can find it here:

http://github.com/adambair/profanity-filter/tree/master

If you encounter any issues, just log your concern at:

http://adambair.lighthouseapp.com/projects/12000-p...

Hopefully someone will find this useful!
96630febb655a1425f1279cc68c1dfa2?d=identicon&s=25 Adam Bair (adambair)
on 2008-06-01 10:49
Adam Bair wrote:

> I just created a Profanity Filter plugin for Rails during the Community
> Code Drive at RailsConf 08.  It's just a one-liner in your model.  You
> can find it here:
>
> http://github.com/adambair/profanity-filter/tree/master
>
> If you encounter any issues, just log your concern at:
>
> http://adambair.lighthouseapp.com/projects/12000-p...
>
> Hopefully someone will find this useful!

Actually, I just renamed this to Fu-fu: The Profanity Filter for Rails.

http://github.com/adambair/fu-fu/tree/master
http://adambair.lighthouseapp.com/projects/12000-f...
E60b2dc57668b5662ce3f07781e41710?d=identicon&s=25 Matthew Rudy Jacobs (matthewrudy)
on 2008-06-01 11:48
Adam Bair wrote:
> Adam Bair wrote:
>
>> I just created a Profanity Filter plugin for Rails during the Community
>> Code Drive at RailsConf 08.  It's just a one-liner in your model.  You
>> can find it here:

Cool...
I wrote my own solution to this a while ago.
Not as elegant, perhaps.

http://pastie.caboo.se/206695
E60b2dc57668b5662ce3f07781e41710?d=identicon&s=25 Matthew Rudy Jacobs (matthewrudy)
on 2008-06-01 11:50
Matthew Rudy Jacobs wrote:

>
> Cool...
> I wrote my own solution to this a while ago.
> Not as elegant, perhaps.
>
> http://pastie.caboo.se/206695

also,
my solution is just a view helper...
hence we don't destroy our user's data.

it may be the case that you want to censor something in one context
(a front page "random comment" perhaps?)
but keep the original content in its true form on the proper page.
E60b2dc57668b5662ce3f07781e41710?d=identicon&s=25 Matthew Rudy Jacobs (matthewrudy)
on 2008-06-01 11:52
Matthew Rudy Jacobs wrote:
> Matthew Rudy Jacobs wrote:
>
>>
>> Cool...
>> I wrote my own solution to this a while ago.
>> Not as elegant, perhaps.
>>
>> http://pastie.caboo.se/206695
>
> also,
> my solution is just a view helper...
> hence we don't destroy our user's data.
>
> it may be the case that you want to censor something in one context
> (a front page "random comment" perhaps?)
> but keep the original content in its true form on the proper page.

and here's my test
http://pastie.caboo.se/206697
96630febb655a1425f1279cc68c1dfa2?d=identicon&s=25 Adam Bair (adambair)
on 2008-06-01 16:13
Matthew Rudy Jacobs wrote:
> Matthew Rudy Jacobs wrote:
>
>>
>> Cool...
>> I wrote my own solution to this a while ago.
>> Not as elegant, perhaps.
>>
>> http://pastie.caboo.se/206695
>
> also,
> my solution is just a view helper...
> hence we don't destroy our user's data.
>
> it may be the case that you want to censor something in one context
> (a front page "random comment" perhaps?)
> but keep the original content in its true form on the proper page.

Yeah, the data modification could be an issue for some folks and will be
changing shortly.

I'll be updating the plugin over the next day or so the original text
will be left in the database:
http://adambair.lighthouseapp.com/projects/12000/t...

I'll also be working on a new (better) regex for curse detection:
http://adambair.lighthouseapp.com/projects/12000/t...

Thanks for the suggestions!  Please feel free to create new tickets.  :)
96630febb655a1425f1279cc68c1dfa2?d=identicon&s=25 Adam Bair (adambair)
on 2008-06-04 19:04
Matthew Rudy Jacobs wrote:
> Matthew Rudy Jacobs wrote:
>
>>
>> Cool...
>> I wrote my own solution to this a while ago.
>> Not as elegant, perhaps.
>>
>> http://pastie.caboo.se/206695
>
> also,
> my solution is just a view helper...
> hence we don't destroy our user's data.
>
> it may be the case that you want to censor something in one context
> (a front page "random comment" perhaps?)
> but keep the original content in its true form on the proper page.

Fu-fu now has two modes: destructive (profanity_filter!) and
non-destructive (profanity_filter).  The non-destructive version will
leave the original text in the database and only filter when called.
The safe method will not modify stored data.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.