public class SpamAnalyzer extends Object
Class which allows applications to detect spam e-mails with self-learning Bayesian filter.
| Constructor and 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. |
| Modifier and Type | Method and Description |
|---|---|
void |
loadDatabase(InputStream stream)
Loads Bayesian database from stream.
|
void |
loadDatabase(String filePath)
Loads Bayesian database from file.
|
void |
reset()
Clears all statistics (Bayesian database).
|
void |
saveDatabase(OutputStream stream)
Saves the Bayesian database to stream.
|
void |
saveDatabase(String filePath)
Saves the Bayesian database to file.
|
double |
test(MailMessage message)
Analyses the message and returns the probability of the message being spam.
|
void |
trainFilter(MailMessage[] ham,
MailMessage[] spam)
Learns from the specified messages as from spam or non-spam source.
|
void |
trainFilter(MailMessage message,
boolean isSpam)
Learns from the specified message as from spam or non-spam source.
|
void |
trainFilter(String text,
boolean isSpam)
Learns from the specified string as from spam or non-spam source.
|
public SpamAnalyzer()
Initialize a new instance of the SpamAnalyzer class.
public SpamAnalyzer(InputStream stream)
Initialize a new instance of the SpamAnalyzer class.
stream - An input stream containing Bayesian database.ArgumentNullException - If stream is null.public SpamAnalyzer(String filePath)
Initialize a new instance of the SpamAnalyzer class.
filePath - The full or relative path to the file containing Bayesian database.ArgumentException - If filePath is null or an empty string.public final void trainFilter(MailMessage[] ham, MailMessage[] spam)
Learns from the specified messages as from spam or non-spam source.
ham - The array of MailMessage objects that is non-spam for training the Bayesian filter.spam - The array of MailMessage objects that is spam for training the Bayesian filter.ArgumentNullException - If ham or spam is null.public final void trainFilter(MailMessage message, boolean isSpam)
Learns from the specified message as from spam or non-spam source.
message - A reference to the MailMessage object representing the message to train the Bayesian filter.isSpam - True if the message is a spam; false if it's a legitimate message.ArgumentNullException - If message is null.public final void trainFilter(String text, boolean isSpam)
Learns from the specified string as from spam or non-spam source.
text - A string value to train the Bayesian filter.isSpam - True if specified text is a spam; false if it's a legitimate text.ArgumentNullException - If text is null.public final double test(MailMessage message)
Analyses the message and returns the probability of the message being spam.
message - MailMessage for test the probability of the message being spam.ArgumentNullException - If message is null.public final void loadDatabase(String filePath)
Loads Bayesian database from file.
filePath - The full or relative path to the file containing Bayesian database.ArgumentException - If filePath is null or an empty string.public final void loadDatabase(InputStream stream)
Loads Bayesian database from stream.
stream - An input stream containing Bayesian database.ArgumentNullException - If stream is null.public final void saveDatabase(String filePath)
Saves the Bayesian database to file.
filePath - The full or relative path to the file containing Bayesian database.ArgumentException - If filePath is null or an empty string.public final void saveDatabase(OutputStream stream)
Saves the Bayesian database to stream.
stream - An output stream containing Bayesian database.ArgumentNullException - If stream is null.public final void reset()
Clears all statistics (Bayesian database).
Copyright (c) 2008-2024 Aspose Pty Ltd. All Rights Reserved.