com.tootsville.hangman
Class Censor

java.lang.Object
  extended by com.tootsville.hangman.Censor
All Implemented Interfaces:
AbstractCensor

public class Censor
extends Object
implements AbstractCensor

Provides chat filtering.

Author:
cnicol, brpocock@star-hope.org, twheys@gmail.com

Field Summary
(package private) static CopyOnWriteArraySet<String> adjacentList
          WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) adjacentList (Censor)
(package private) static CopyOnWriteArraySet<String> blackList
          WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) blackList (Censor)
(package private) static Pattern numberPattern
          Removing digits
(package private) static CopyOnWriteArraySet<String> oneList
          WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) oneList (Censor)
(package private) static Pattern sgmlEntityPattern
          Pattern to remove SGML-type entities
(package private) static Pattern shoutingPattern
          No shouting
(package private) static Pattern symbolsPattern
          Symbols to be removed before filtering a sentence
(package private) static ConcurrentHashMap<String,Integer> weights
          WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) weights (Censor)
(package private) static CopyOnWriteArraySet<String> whiteList
          WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) whiteList (Censor)
(package private) static CopyOnWriteArraySet<String> worseList
          WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) worseList (Censor)
 
Constructor Summary
Censor()
           
 
Method Summary
static void addToAdjacentList(String word)
          Add a word to the adjacent word list.
static void addToBlackList(String word)
          Add a word to the Black list.
static void addToWhiteList(String word)
          Add a word to the White list.
static void addToWorseList(String word)
          Add a word to the Worse (Red) list.
private static FilterResult checkAdjacentLists(String token)
          Check if a token matches a full word in any of the filtering lists.
private static FilterResult checkAdjacentTokens(List<String> tokens)
          WRITEME: document this method
 FilterResult checkLists(String token)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
private  FilterResult checkTokens(List<String> tokens)
          WRITEME: document this method
 void destroy()
          Release the hash tables.
 FilterResult filterMessage(String text)
          Filter the message.
static int getBlackListLength()
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 int getWhiteListLength()
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
static int getWorseListLength()
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
static void init()
          Initialize the filtering word sets.
private static boolean inWhitelist(String word, CopyOnWriteArraySet<String> copyOnWriteArraySet)
          Determine if the word is a white listed word.
 void loadLists(Connection dbh)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void prime(Connection databaseConnection)
          WRITEME: Document this method brpocock@star-hope.org
 void reloadLists(Connection dbh)
          Clear all censors and reload them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

adjacentList

static volatile CopyOnWriteArraySet<String> adjacentList
WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) adjacentList (Censor)


blackList

static volatile CopyOnWriteArraySet<String> blackList
WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) blackList (Censor)


numberPattern

static final Pattern numberPattern
Removing digits


oneList

static volatile CopyOnWriteArraySet<String> oneList
WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) oneList (Censor)


sgmlEntityPattern

static final Pattern sgmlEntityPattern
Pattern to remove SGML-type entities


shoutingPattern

static final Pattern shoutingPattern
No shouting


symbolsPattern

static final Pattern symbolsPattern
Symbols to be removed before filtering a sentence


weights

static volatile ConcurrentHashMap<String,Integer> weights
WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) weights (Censor)


whiteList

static volatile CopyOnWriteArraySet<String> whiteList
WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) whiteList (Censor)


worseList

static volatile CopyOnWriteArraySet<String> worseList
WRITEME: document this field (brpocock@star-hope.org, Nov 5, 2009) worseList (Censor)

Constructor Detail

Censor

public Censor()
Method Detail

addToAdjacentList

public static void addToAdjacentList(String word)
Add a word to the adjacent word list.

Parameters:
word - WRITEME

addToBlackList

public static void addToBlackList(String word)
Add a word to the Black list.

Parameters:
word - WRITEME

addToWhiteList

public static void addToWhiteList(String word)
Add a word to the White list.

Parameters:
word - WRITEME

addToWorseList

public static void addToWorseList(String word)
Add a word to the Worse (Red) list.

Parameters:
word - WRITEME

checkAdjacentLists

private static FilterResult checkAdjacentLists(String token)
Check if a token matches a full word in any of the filtering lists.

Parameters:
token - to be checked.
Returns:
FilterResult indicating the kind of match found.

checkAdjacentTokens

private static FilterResult checkAdjacentTokens(List<String> tokens)
WRITEME: document this method

Parameters:
tokens - WRITEME
Returns:
WRITEME

getBlackListLength

public static int getBlackListLength()
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Returns:
WRITEME

getWorseListLength

public static int getWorseListLength()
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Returns:
WRITEME

init

public static void init()
Initialize the filtering word sets.


inWhitelist

private static boolean inWhitelist(String word,
                                   CopyOnWriteArraySet<String> copyOnWriteArraySet)
Determine if the word is a white listed word.

Parameters:
word - Word to check.
copyOnWriteArraySet - List to check.
Returns:
true if the word is in the list.

checkLists

public FilterResult checkLists(String token)
Description copied from interface: AbstractCensor
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Specified by:
checkLists in interface AbstractCensor
Parameters:
token - WRITEME
Returns:
WRITEME
See Also:
AbstractCensor.checkLists(java.lang.String)

checkTokens

private FilterResult checkTokens(List<String> tokens)
WRITEME: document this method

Parameters:
tokens - WRITEME
Returns:
WRITEME

destroy

public void destroy()
Release the hash tables.


filterMessage

public FilterResult filterMessage(String text)
Description copied from interface: AbstractCensor
Filter the message.

Specified by:
filterMessage in interface AbstractCensor
Parameters:
text - WRITEME
Returns:
true if message should be filtered.
See Also:
AbstractCensor.filterMessage(java.lang.String)

getWhiteListLength

public int getWhiteListLength()
Description copied from interface: AbstractCensor
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Specified by:
getWhiteListLength in interface AbstractCensor
Returns:
WRITEME
See Also:
AbstractCensor.getWhiteListLength()

loadLists

public void loadLists(Connection dbh)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Specified by:
loadLists in interface AbstractCensor
Parameters:
dbh - A live database connection from which to load the censorship lists

prime

public void prime(Connection databaseConnection)
Description copied from interface: AbstractCensor
WRITEME: Document this method brpocock@star-hope.org

Specified by:
prime in interface AbstractCensor
Parameters:
databaseConnection - An open database connection over which the censorship records can be loaded

reloadLists

public void reloadLists(Connection dbh)
Clear all censors and reload them.

Specified by:
reloadLists in interface AbstractCensor
Parameters:
dbh - A live database connection from which to load the censorship lists