Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var currentPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            var spamPath    = Path.Combine(currentPath, @"Resources", @"spam.txt");
            var hamPath     = Path.Combine(currentPath, @"Resources", @"ham.txt");

            filter.Train(spamPath, hamPath);
            CreateWebHostBuilder(args).Build().Run();
        }
Exemplo n.º 2
0
        public void Test()
        {
            var corpus      = @"不愧是DIO!我们不敢做的事,他毫不在乎地做了!真是佩服,真是我们的偶像!";
            var currentPath = @".\";
            var spamPath    = Path.Combine(currentPath, @"Resources", @"spam.txt");
            var hamPath     = Path.Combine(currentPath, @"Resources", @"ham.txt");

            var spamDetector = new SpamDetector();

            spamDetector.Train(spamPath, hamPath);

            Assert.AreEqual(spamDetector.IsSpam(corpus), CategorizationResult.Second);
        }
Exemplo n.º 3
0
        public void LongTest()
        {
            var corpus      = @"不愧是DIO!我们不敢做的事,他毫不在乎地做了!真是佩服,真是我们的偶像!";
            var currentPath = @".\";
            var spamPath    = Path.Combine(currentPath, @"Resources", @"spam.txt");
            var hamPath     = Path.Combine(currentPath, @"Resources", @"ham.txt");

            var spamDetector = new SpamDetector();

            spamDetector.Train(spamPath, hamPath);
            var utf8  = new UTF8Encoding(false);
            var spams = File.ReadAllLines(spamPath, utf8);
            var hams  = File.ReadAllLines(hamPath, utf8);
            var r0    = 0;

            Parallel.For(72001, 80000, i =>
            {
                var result = spamDetector.IsSpam(spams[i]);
                if (result == CategorizationResult.First)
                {
                    Interlocked.Increment(ref r0);
                }
            });
            var r = r0 / 8000d * 100;

            Console.WriteLine($@"{r}%");
            Assert.IsTrue(r > 0.97);
            var r1 = 0;

            Parallel.For(648001, 720000, i =>
            {
                var result = spamDetector.IsSpam(hams[i]);
                if (result != CategorizationResult.First)
                {
                    Interlocked.Increment(ref r1);
                }
            });
            r = r1 / 72000d * 100;
            Console.WriteLine($@"{r}%");
            Assert.IsTrue(r > 0.97);
            Assert.AreEqual(spamDetector.IsSpam(corpus), CategorizationResult.Second);
        }