SpamAnalyzer

Inheritance: java.lang.Object

public class SpamAnalyzer

Class which allows applications to detect spam e-mails with self-learning Bayesian filter.

Constructors

ConstructorDescription
SpamAnalyzer()Initialize a new instance of the SpamAnalyzer class.
SpamAnalyzer(InputStream stream)Initialize a new instance of the SpamAnalyzer class.
SpamAnalyzer(String filePath)Initialize a new instance of the SpamAnalyzer class.

Methods

MethodDescription
equals(Object arg0)
getClass()
hashCode()
loadDatabase(InputStream stream)Loads Bayesian database from stream.
loadDatabase(String filePath)Loads Bayesian database from file.
notify()
notifyAll()
reset()Clears all statistics (Bayesian database).
saveDatabase(OutputStream stream)Saves the Bayesian database to stream.
saveDatabase(String filePath)Saves the Bayesian database to file.
test(MailMessage message)Analyses the message and returns the probability of the message being spam.
toString()
trainFilter(MailMessage message, boolean isSpam)Learns from the specified message as from spam or non-spam source.
trainFilter(MailMessage[] ham, MailMessage[] spam)Learns from the specified messages as from spam or non-spam source.
trainFilter(String text, boolean isSpam)Learns from the specified string as from spam or non-spam source.
wait()
wait(long arg0)
wait(long arg0, int arg1)

SpamAnalyzer()

public SpamAnalyzer()

Initialize a new instance of the SpamAnalyzer class.

SpamAnalyzer(InputStream stream)

public SpamAnalyzer(InputStream stream)

Initialize a new instance of the SpamAnalyzer class.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamAn input stream containing Bayesian database.

SpamAnalyzer(String filePath)

public SpamAnalyzer(String filePath)

Initialize a new instance of the SpamAnalyzer class.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe full or relative path to the file containing Bayesian database.

equals(Object arg0)

public boolean equals(Object arg0)

Parameters:

ParameterTypeDescription
arg0java.lang.Object

Returns: boolean

getClass()

public final native Class<?> getClass()

Returns: java.lang.Class

hashCode()

public native int hashCode()

Returns: int

loadDatabase(InputStream stream)

public final void loadDatabase(InputStream stream)

Loads Bayesian database from stream.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamAn input stream containing Bayesian database.

loadDatabase(String filePath)

public final void loadDatabase(String filePath)

Loads Bayesian database from file.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe full or relative path to the file containing Bayesian database.

notify()

public final native void notify()

notifyAll()

public final native void notifyAll()

reset()

public final void reset()

Clears all statistics (Bayesian database).

saveDatabase(OutputStream stream)

public final void saveDatabase(OutputStream stream)

Saves the Bayesian database to stream.

Parameters:

ParameterTypeDescription
streamjava.io.OutputStreamAn output stream containing Bayesian database.

saveDatabase(String filePath)

public final void saveDatabase(String filePath)

Saves the Bayesian database to file.

Parameters:

ParameterTypeDescription
filePathjava.lang.StringThe full or relative path to the file containing Bayesian database.

test(MailMessage message)

public final double test(MailMessage message)

Analyses the message and returns the probability of the message being spam.

Parameters:

ParameterTypeDescription
messageMailMessageMailMessage for test the probability of the message being spam.

Returns: double - A double value in 0-1 range, where 0 corresponds to “definitely non-spam” (0% spam probability) and 1 corresponds to “definitely spam” (100% spam probability).

toString()

public String toString()

Returns: java.lang.String

trainFilter(MailMessage message, boolean isSpam)

public final void trainFilter(MailMessage message, boolean isSpam)

Learns from the specified message as from spam or non-spam source.

Parameters:

ParameterTypeDescription
messageMailMessageA reference to the MailMessage object representing the message to train the Bayesian filter.
isSpambooleanTrue if the message is a spam; false if it’s a legitimate message.

trainFilter(MailMessage[] ham, MailMessage[] spam)

public final void trainFilter(MailMessage[] ham, MailMessage[] spam)

Learns from the specified messages as from spam or non-spam source.

Parameters:

ParameterTypeDescription
hamMailMessage[]The array of MailMessage objects that is non-spam for training the Bayesian filter.
spamMailMessage[]The array of MailMessage objects that is spam for training the Bayesian filter.

trainFilter(String text, boolean isSpam)

public final void trainFilter(String text, boolean isSpam)

Learns from the specified string as from spam or non-spam source.

Parameters:

ParameterTypeDescription
textjava.lang.StringA string value to train the Bayesian filter.
isSpambooleanTrue if specified text is a spam; false if it’s a legitimate text.

wait()

public final void wait()

wait(long arg0)

public final native void wait(long arg0)

Parameters:

ParameterTypeDescription
arg0long

wait(long arg0, int arg1)

public final void wait(long arg0, int arg1)

Parameters:

ParameterTypeDescription
arg0long
arg1int