示例#1
0
        private void button2_Click(object sender, EventArgs e)
        {
            //进行计时
            Stopwatch time = new Stopwatch();

            time.Start();
            //读取短信
            string content = textBox1.Text;
            knn    a       = new knn();

            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("KNN测试总耗时:" + 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("综合评估为:垃圾短信");
            }
        }
示例#2
0
        private void button2_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)
            {
                knn a = new knn();
                a.Compute(row["sms"].ToString());
                if (a.getnorchance > a.getinfchance && a.getnorchance > a.getspachance)
                {
                    row["knn分类"] = "正常短信";
                }
                else if (a.getinfchance > a.getnorchance && a.getinfchance > a.getspachance)
                {
                    row["knn分类"] = "通知短信";
                }
                else
                {
                    row["knn分类"] = "垃圾短信";
                }
            }
            //数据提交到数据库
            adapter.Update(dt);
            //更新datagridview数据
            this.notyetTableAdapter.Fill(this.短信DataSet.notyet);
            //计时
            time.Stop();
            TimeSpan ts2 = time.Elapsed;

            MessageBox.Show("分类完成!\n耗时:" + ts2.TotalSeconds.ToString() + "秒", "提示");
        }