com.aspose.email

Interfaces

Classes

Enums

Exceptions

com.aspose.email

Class SpamAnalyzer



  • public class SpamAnalyzer
    extends Object

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

    • Constructor Detail

      • SpamAnalyzer

        public SpamAnalyzer()

        Initialize a new instance of the SpamAnalyzer class.

      • SpamAnalyzer

        public SpamAnalyzer(InputStream stream)

        Initialize a new instance of the SpamAnalyzer class.

        Parameters:
        stream - An input stream containing Bayesian database.
        Throws:
        ArgumentNullException - If stream is null.
      • SpamAnalyzer

        public SpamAnalyzer(String filePath)

        Initialize a new instance of the SpamAnalyzer class.

        Parameters:
        filePath - The full or relative path to the file containing Bayesian database.
        Throws:
        ArgumentException - If filePath is null or an empty string.
    • Method Detail

      • trainFilter

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

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

        Parameters:
        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.
        Throws:
        ArgumentNullException - If ham or spam is null.
      • trainFilter

        public final void trainFilter(MailMessage message,
                       boolean isSpam)

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

        Parameters:
        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.
        Throws:
        ArgumentNullException - If message is null.
      • trainFilter

        public final void trainFilter(String text,
                       boolean isSpam)

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

        Parameters:
        text - A string value to train the Bayesian filter.
        isSpam - True if specified text is a spam; false if it's a legitimate text.
        Throws:
        ArgumentNullException - If text is null.
      • test

        public final double test(MailMessage message)

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

        Parameters:
        message - MailMessage for test the probability of the message being spam.
        Returns:
        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).
        Throws:
        ArgumentNullException - If message is null.
      • loadDatabase

        public final void loadDatabase(String filePath)

        Loads Bayesian database from file.

        Parameters:
        filePath - The full or relative path to the file containing Bayesian database.
        Throws:
        ArgumentException - If filePath is null or an empty string.
      • loadDatabase

        public final void loadDatabase(InputStream stream)

        Loads Bayesian database from stream.

        Parameters:
        stream - An input stream containing Bayesian database.
        Throws:
        ArgumentNullException - If stream is null.
      • saveDatabase

        public final void saveDatabase(String filePath)

        Saves the Bayesian database to file.

        Parameters:
        filePath - The full or relative path to the file containing Bayesian database.
        Throws:
        ArgumentException - If filePath is null or an empty string.
      • saveDatabase

        public final void saveDatabase(OutputStream stream)

        Saves the Bayesian database to stream.

        Parameters:
        stream - An output stream containing Bayesian database.
        Throws:
        ArgumentNullException - If stream is null.
      • reset

        public final void reset()

        Clears all statistics (Bayesian database).