Exemple #1
0
 //проверка текста и обучение программы
 private void button5_Click(object sender, EventArgs e)
 {
     if (textBox1.Text != "")
     {
         bool   isSpam       = false;
         double SpamPercent  = 0.5;
         string inputContent = textBox1.Text;
         СleaningUpUnnecessary(ref inputContent);
         string[]      AllWords = Separator(inputContent);
         List <string> words    = new List <string>();
         foreach (var word in AllWords)
         {
             if (word.Length > 4 && word.Length < 100 && word.Substring(0, 4) != "http")
             {
                 words.Add(word);
             }
         }
         Dictionary <string, int> dictionary  = WordCounter(words);
         List <string>            words2check = WordCheck(dictionary);
         Checking(ref SpamPercent, words2check);
         SpamTextResult(SpamPercent, ref isSpam);
         ManualSetting(ref isSpam);
         BayesTheorem.Learning(words2check, isSpam);
         label7.Text = SpamPercent.ToString();
     }
 }
Exemple #2
0
        public void Checking(ref double SpamPercent, List <string> words2check)
        {
            double NeSpamPersent = 0;

            string DBaseFirstValue = BayesTheorem.FindSpamWord(words2check[0]);

            if (DBaseFirstValue == "")
            {
                DBaseFirstValue = "0,5";
            }
            SpamPercent   = Convert.ToDouble(DBaseFirstValue);
            NeSpamPersent = 1 - SpamPercent;
            bool isTheFirst = true;



            foreach (var word2check in words2check)
            {
                if (isTheFirst)
                {
                    isTheFirst = false;
                    continue;
                }
                string DBaseValue = BayesTheorem.FindSpamWord(word2check);
                if (DBaseValue == "")
                {
                    DBaseValue = "0,5";
                }

                double P_X = SpamPercent;
                double P_Y = Convert.ToDouble(DBaseValue);

                SpamPercent   *= P_Y;
                NeSpamPersent *= (1 - P_Y);

                SpamPercent = P_X * P_Y / (P_X * P_Y + (1 - P_X) * (1 - P_Y));
            }

            //SpamPercent = SpamPercent / (SpamPercent + NeSpamPersent);
        }