org.apache.james.ai.classic
Class JDBCBayesianAnalyzer

java.lang.Object
  extended by org.apache.james.ai.classic.BayesianAnalyzer
      extended by org.apache.james.ai.classic.JDBCBayesianAnalyzer
All Implemented Interfaces:
Log

public class JDBCBayesianAnalyzer
extends BayesianAnalyzer
implements Log

Manages the persistence of the spam bayesian analysis corpus using a JDBC database.

This class is abstract to allow implementations to take advantage of different logging capabilities/interfaces in different parts of the code.

Since:
2.3.0

Field Summary
static String DATABASE_LOCK
          Public object representing a lock on database activity.
 
Constructor Summary
JDBCBayesianAnalyzer()
           
JDBCBayesianAnalyzer(Log log)
           
 
Method Summary
static long getLastDatabaseUpdateTime()
          Getter for static lastDatabaseUpdateTime.
 Log getLog()
          Gets the current log.
 String getSqlFileName()
          Getter for property sqlFileName.
 Map<String,String> getSqlParameters()
          Getter for property sqlParameters.
 void initSqlQueries(Connection conn, Document sqlConfiguration)
          Initializes the sql query environment from the SqlResources file.
 void loadHamNSpam(Connection conn)
          Loads the token frequencies from the database.
 void log(String errorString)
          Logs errors.
 void log(String errorString, Throwable t)
          Logs errors.
 void resetData(Connection conn)
          Reset all trained data
 void setLog(Log log)
          Sets the current log.
 void setSqlFileName(String sqlFileName)
          Setter for property sqlFileName.
 void setSqlParameters(Map<String,String> sqlParameters)
          Setter for property sqlParameters.
static void touchLastDatabaseUpdateTime()
          Sets static lastDatabaseUpdateTime to System.currentTimeMillis().
 void updateHamTokens(Connection conn)
          Updates the database with new "ham" token frequencies.
 void updateSpamTokens(Connection conn)
          Updates the database with new "spam" token frequencies.
 
Methods inherited from class org.apache.james.ai.classic.BayesianAnalyzer
addHam, addSpam, buildCorpus, clear, computeSpamProbability, getCorpus, getHamMessageCount, getHamTokenCounts, getSpamMessageCount, getSpamTokenCounts, setCorpus, setHamMessageCount, setHamTokenCounts, setSpamMessageCount, setSpamTokenCounts, tokenCountsClear
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATABASE_LOCK

public static final String DATABASE_LOCK
Public object representing a lock on database activity.

See Also:
Constant Field Values
Constructor Detail

JDBCBayesianAnalyzer

public JDBCBayesianAnalyzer()

JDBCBayesianAnalyzer

public JDBCBayesianAnalyzer(Log log)
Method Detail

getLastDatabaseUpdateTime

public static long getLastDatabaseUpdateTime()
Getter for static lastDatabaseUpdateTime.

Returns:
Value of property lastDatabaseUpdateTime.

touchLastDatabaseUpdateTime

public static void touchLastDatabaseUpdateTime()
Sets static lastDatabaseUpdateTime to System.currentTimeMillis().


getLog

public Log getLog()
Gets the current log.

Returns:
current log, not null

setLog

public void setLog(Log log)
Sets the current log.

Parameters:
log - not null

getSqlFileName

public String getSqlFileName()
Getter for property sqlFileName.

Returns:
Value of property sqlFileName.

setSqlFileName

public void setSqlFileName(String sqlFileName)
Setter for property sqlFileName.

Parameters:
sqlFileName - New value of property sqlFileName.

getSqlParameters

public Map<String,String> getSqlParameters()
Getter for property sqlParameters.

Returns:
Value of property sqlParameters.

setSqlParameters

public void setSqlParameters(Map<String,String> sqlParameters)
Setter for property sqlParameters.

Parameters:
sqlParameters - New value of property sqlParameters.

loadHamNSpam

public void loadHamNSpam(Connection conn)
                  throws SQLException
Loads the token frequencies from the database.

Parameters:
conn - The connection for accessing the database
Throws:
SQLException - If a database error occurs

updateHamTokens

public void updateHamTokens(Connection conn)
                     throws SQLException
Updates the database with new "ham" token frequencies.

Parameters:
conn - The connection for accessing the database
Throws:
SQLException - If a database error occurs

updateSpamTokens

public void updateSpamTokens(Connection conn)
                      throws SQLException
Updates the database with new "spam" token frequencies.

Parameters:
conn - The connection for accessing the database
Throws:
SQLException - If a database error occurs

resetData

public void resetData(Connection conn)
               throws SQLException
Reset all trained data

Parameters:
conn - The connection for accessing the database
Throws:
SQLException - If a database error occours

initSqlQueries

public void initSqlQueries(Connection conn,
                           Document sqlConfiguration)
                    throws Exception
Initializes the sql query environment from the SqlResources file. Will look for conf/sqlResources.xml.

Parameters:
conn - The connection for accessing the database
sqlConfiguration - The sqlResources configuration document
Throws:
Exception - If any error occurs

log

public void log(String errorString)
Logs errors.

Specified by:
log in interface Log
Parameters:
errorString - the error message generated

log

public void log(String errorString,
                Throwable t)
Logs errors.

Specified by:
log in interface Log
Parameters:
errorString - the error message generated
t - exception


Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.