SpamAnalyzer

Inheritance: java.lang.Object

public class SpamAnalyzer

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

Constructors

Constructor Description
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

Method Description
trainFilter(MailMessage[] ham, MailMessage[] spam) Learns from the specified messages as from spam or non-spam source.
trainFilter(MailMessage message, boolean isSpam) Learns from the specified message as from spam or non-spam source.
trainFilter(String text, boolean isSpam) Learns from the specified string as from spam or non-spam source.
test(MailMessage message) Analyses the message and returns the probability of the message being spam.
loadDatabase(String filePath) Loads Bayesian database from file.
loadDatabase(InputStream stream) Loads Bayesian database from stream.
saveDatabase(String filePath) Saves the Bayesian database to file.
saveDatabase(OutputStream stream) Saves the Bayesian database to stream.
reset() Clears all statistics (Bayesian database).

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:

Parameter Type Description
stream java.io.InputStream An input stream containing Bayesian database.

SpamAnalyzer(String filePath)

public SpamAnalyzer(String filePath)

Initialize a new instance of the SpamAnalyzer class.

Parameters:

Parameter Type Description
filePath java.lang.String The full or relative path to the file containing Bayesian database.

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:

Parameter Type Description
ham com.aspose.email.MailMessage[] The array of MailMessage objects that is non-spam for training the Bayesian filter.
spam com.aspose.email.MailMessage[] The array of MailMessage objects that is spam for training the Bayesian filter.

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:

Parameter Type Description
message MailMessage A reference to the MailMessage object representing the message to train the Bayesian filter.
isSpam boolean True if the message is a spam; false if it’s a legitimate message.

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:

Parameter Type Description
text java.lang.String A string value to train the Bayesian filter.
isSpam boolean True if specified text is a spam; false if it’s a legitimate text.

test(MailMessage message)

public final double test(MailMessage message)

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

Parameters:

Parameter Type Description
message MailMessage MailMessage 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).

loadDatabase(String filePath)

public final void loadDatabase(String filePath)

Loads Bayesian database from file.

Parameters:

Parameter Type Description
filePath java.lang.String The full or relative path to the file containing Bayesian database.

loadDatabase(InputStream stream)

public final void loadDatabase(InputStream stream)

Loads Bayesian database from stream.

Parameters:

Parameter Type Description
stream java.io.InputStream An input stream containing Bayesian database.

saveDatabase(String filePath)

public final void saveDatabase(String filePath)

Saves the Bayesian database to file.

Parameters:

Parameter Type Description
filePath java.lang.String The full or relative path to the file containing Bayesian database.

saveDatabase(OutputStream stream)

public final void saveDatabase(OutputStream stream)

Saves the Bayesian database to stream.

Parameters:

Parameter Type Description
stream java.io.OutputStream An output stream containing Bayesian database.

reset()

public final void reset()

Clears all statistics (Bayesian database).