PHP Classes

Intelligent Censor: Replace rude words by acceptable alternatives

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 765 All time: 4,419 This week: 455Up
Version License PHP version Categories
intelligentcensor 2.0GNU General Publi...5.0PHP 5, Text processing
Description 

Author

This class can be used to process text and replace rude words by acceptable alternatives.

It can take an English text that may have rude words and can replace such words or variants with acceptable alternative words.

The replaced words can preserve the original words case and common English suffixes.

Innovation Award
PHP Programming Innovation award nominee
September 2008
Number 5


Prize: One copy of the Zend Studio
Sites that provide means for the users to communicate without human moderation, like for instance forums and chat sites, sometimes users may use rude words that are offensive to other users.

In that case, the offenses could be avoided if rude words could be censored automatically.

This class provides an automated solution that censors some well known rude words by more acceptable words that express the same ideas without being so offensive.

Manuel Lemos
Picture of sk89q
Name: sk89q <contact>
Classes: 8 packages by
Country: United States United States
Innovation award
Innovation award
Nominee: 5x

Details

IntelligentCensor (c) Copyright 2006-2008 sk89q <http://sk89q.therisenrealm.com> Released under GPLv2 Introduction ------------ While most word filters work by replacing fuzzy matches with a static replacement, this library does it differently. In many occasions, visitors to a site may try to express anger and, without any ill intention, spew out some vulgar language. Because most word filter libraries use static replacements, the original message and its tone are lost. However, IntelligentCensor uses dynamic replacements that adapt to each replaced word. If a particular filtered word is written in all-caps to express a heavy tone, its resulting replacement will be in all-caps as well. In addition, if a filtered word has any prefixes or suffixes applied to it ([sic] damn vs. damnit), this library can handle those too, and even change the ending of the replacement word according to (some) basic rules of English. The library is written in PHP and is released GNU General Public License (GPL) version two. Usage ----- Construct an instance of IntelligentCensor with the list of censors (associative array) and list of exclusions (associative array) for the constructor's parameters. Then, just call the censor method on he text. For filter definitions, you can use * as a wildcard character. To use the dynamic prefix and suffix handling abilities of this library, place % at the beginning or end of the filter definition (it won't work in any other place). Also, filters should not use special symbols, because the regular expression that is in use won't support them. See the example code below (it's also in example.php). <?php require_once "IntelligentCensor.php"; // * are not expanded // % are expanded, and but they will only work when placed at either the // beginning or ending of the word $censors = array( '*damn%' => 'darn', 'whore%' => 'people', 'bastard*' => 'happyperson', '*ho' => 'person', ); // Can use * wildcards $censors_exclusion = array( 'echo*', ); $icensor = new IntelligentCensor($censors, $censors_exclusion); echo $icensor->censor("you're all DIETYDAMNING bastardly wHOres! you echo ho!"); // Result: you're all DARNING happyperson pEOples! you echo person! ?>

  Files folder image Files (3)  
File Role Description
Accessible without login Plain text file example.php Example Example
Plain text file IntelligentCensor.php Class Main class
Accessible without login Plain text file README.txt Doc. Readme

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:765
This week:0
All time:4,419
This week:455Up