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

Namespace: MailBee.AntiSpam
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
public void TrainFilter(
	MailMessage message,
	bool isSpam
)

Parameters

message
Type: MailBee.MimeMailMessage
A reference to the MailMessage object representing the message to train the Bayesian filter.
isSpam
Type: SystemBoolean
true if the message is a spam; false if it's a legitimate message.
Exceptions
ExceptionCondition
MailBeeInvalidArgumentExceptionmessage is a null reference (Nothing in Visual Basic).
Remarks

Prior to starting using the Bayesian filter to detect spam messages you should learn it with a number of spam and non-spam messages. The filter becomes effective if the database contains at least hundreds of different spam and non-spam messages.

This method updates the database only in memory. To store the database to disk, use SaveDatabase(String, String) method.

Examples

This sample trains Bayesian database with spam and non-spam messages and saves it to disk.

It's assumed the spam and non-spam samples are .EML files located in C:\AntiSpam\Spam and C:\AntiSpam\NonSpam folders respectively. The database itself (spam.dat and nonspam.dat) will be saved in C:\AntiSpam folder.

// To use the code below, import these namespaces at the top of your code.
using System.IO;
using MailBee.Mime;
using MailBee.AntiSpam;

class Sample
{
    static void Main(string[] args)
    {
        BayesFilter filter = new BayesFilter();
        MailMessage msg = new MailMessage();

        filter.LoadDatabase(@"C:\AntiSpam\spam.dat", @"C:\AntiSpam\nonspam.dat");

        // Train Bayesian filter for spam messages.
        string[] files = Directory.GetFiles(@"C:\AntiSpam\Spam", "*.eml");
        foreach (string file in files)
        {
            msg.LoadMessage(file);
            filter.TrainFilter(msg, true); // Mark as spam.
        }

        // Train Bayesian filter for non-spam messages.
        files = Directory.GetFiles(@"C:\AntiSpam\NonSpam", "*.eml");
        foreach (string file in files)
        {
            msg.LoadMessage(file);
            filter.TrainFilter(msg, false); // Mark as non-spam.
        }

        // Save Bayesian database to disk.
        filter.SaveDatabase(@"C:\AntiSpam\spam.dat", @"C:\AntiSpam\nonspam.dat");
    }
}
See Also