Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //进行计时
            Stopwatch time = new Stopwatch();

            time.Start();
            //数据库连接
            string          conStr     = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\Debug\短信.mdb";
            OleDbConnection connection = new OleDbConnection(conStr);
            OleDbCommand    cmd        = connection.CreateCommand();

            cmd.CommandText = "select * from notyet";
            OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
            //创建commandbuider对象
            OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(adapter);

            adapter.InsertCommand = cmdBuilder.GetInsertCommand();
            adapter.DeleteCommand = cmdBuilder.GetDeleteCommand();
            adapter.UpdateCommand = cmdBuilder.GetUpdateCommand();
            //创建datatable对象
            DataTable dt = new DataTable();

            adapter.Fill(dt);
            foreach (DataRow row in dt.Rows)
            {
                bayes a = new bayes();
                a.Compute(row["sms"].ToString());
                if (a.getnorchance > a.getinfchance && a.getnorchance > a.getspachance)
                {
                    row["bayes分类"] = "正常短信";
                }
                else if (a.getinfchance > a.getnorchance && a.getinfchance > a.getspachance)
                {
                    row["bayes分类"] = "通知短信";
                }
                else
                {
                    row["bayes分类"] = "垃圾短信";
                }
            }
            //数据提交到数据库
            adapter.Update(dt);
            //更新datagridview数据
            this.notyetTableAdapter.Fill(this.短信DataSet.notyet);
            //计时
            time.Stop();
            TimeSpan ts2 = time.Elapsed;

            MessageBox.Show("分类完成!\n耗时:" + ts2.TotalSeconds.ToString() + "秒", "提示");
        }
Exemplo n.º 2
0
 private void button5_Click(object sender, EventArgs e)
 {
     try
     {
         //进行计时
         Stopwatch time = new Stopwatch();
         time.Start();
         //读入textBox1的短信,并开始分词
         string content = textBox1.Text;
         //遍历训练好的train文档的每一行,计算文本属于类一,类二,类三的总似然
         bayes a = new bayes();
         a.Compute(content);
         //计时
         time.Stop();
         TimeSpan ts2 = time.Elapsed;
         listBox1.Items.Clear();
         listBox1.Items.Add("为正常短信概率为:" + (100 * a.getnorchance).ToString() + "%");
         listBox1.Items.Add("为通知短信概率为:" + (100 * a.getinfchance).ToString() + "%");
         listBox1.Items.Add("为垃圾短信概率为:" + (100 * a.getspachance).ToString() + "%");
         listBox1.Items.Add("贝叶斯测试总耗时:" + ts2.TotalSeconds + "秒");
         if (a.getnorchance > a.getinfchance && a.getnorchance > a.getspachance)
         {
             listBox1.Items.Add("综合评估为:正常短信");
         }
         else if (a.getinfchance > a.getnorchance && a.getinfchance > a.getspachance)
         {
             listBox1.Items.Add("综合评估为:通知短信");
         }
         else
         {
             listBox1.Items.Add("综合评估为:垃圾短信");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }