using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using Expat.Bayesian; namespace SpamFilterSample { public enum MailType { Safe, Sport, Unknown, Spam, } public class MailSpamFilter { private SpamFilter _SpamFilter = new SpamFilter(); public Double NormalValue { get; set; } public Double SpamValue { get; set; } public void LoadData() { Corpus spam = new Corpus(); Corpus normal = new Corpus(); String s = ""; s = File.ReadAllText("Spam.txt"); spam.LoadFromReader(new StringReader(s)); s = File.ReadAllText("NotSpam.txt"); spam.LoadFromReader(new StringReader(s)); _SpamFilter.Load(normal, spam); } public MailType Test(String text) { Double d = _SpamFilter.Test(text); if (d < this.NormalValue) { return MailType.Safe; } else if (d > this.SpamValue) { return MailType.Spam; } return MailType.Unknown; } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The MIT License