コード例 #1
0
 private void button__SearchC_Click(object sender, EventArgs e)
 {
     if (Config.RemoveUselessInfo)//移除无用信息
     {
         browserForm.Jump("http://www.baidu.com/s?wd=" + AnalyzeProblem.RemoveUselessInfo(textBox_Problem.Text + " " + textBox_AnswerC.Text));
     }
     else
     {
         browserForm.Jump("http://www.baidu.com/s?wd=" + SearchEngine.UrlEncode(textBox_Problem.Text + " " + textBox_AnswerC.Text));
     }
 }
コード例 #2
0
        private void button_SearchB_Click(object sender, EventArgs e)
        {
            string url;

            if (!Config.UseSoGou)
            {
                url = "http://www.baidu.com/s?wd=";
            }
            else
            {
                url = "https://www.sogou.com/web?query=";
            }

            if (Config.RemoveUselessInfo)//移除无用信息
            {
                browserForm.Jump(url + AnalyzeProblem.RemoveUselessInfo(textBox_Problem.Text + " " + textBox_AnswerB.Text));
            }
            else
            {
                browserForm.Jump(url + SearchEngine.UrlEncode(textBox_Problem.Text + " " + textBox_AnswerB.Text));
            }
        }
コード例 #3
0
        private void button_SearchD_Click(object sender, EventArgs e)
        {
            string url;

            if (!Config.UseSoGou)
            {
                url = "http://www.baidu.com/s?wd=";
            }
            else
            {
                url = "https://www.sogou.com/web?query=";
            }

            if (Config.RemoveUselessInfo)//移除无用信息
            {
                url += SearchEngine.UrlEncode(AnalyzeProblem.RemoveUselessInfo(textBox_Problem.Text + " " + textBox_AnswerD.Text));
            }
            else
            {
                url += SearchEngine.UrlEncode(textBox_Problem.Text + " " + textBox_AnswerD.Text);
            }
            // browserForm.Jump(url);
            browserForm.HighlightAndShowPage(url, new string[] { "null", "null", "null", textBox_AnswerD.Text });
        }
コード例 #4
0
        private void SolveProblem()//答题
        {
            if (!checkBox_InPutProblem.Checked)
            {
                label_Message.Text      = "正在获取手机界面";
                label_Message.ForeColor = Color.Orange;
                //获取屏幕截图
                string screenShotPath;
                byte[] smallScreenShot;
                try
                {
                    if (Config.UseEmulator)//是否为模拟器
                    {
                        smallScreenShot = BitmapOperation.CutScreen(new Point(Config.CutX, Config.CutY), new Size(Config.CutWidth, Config.CutHeight));
                    }
                    else
                    {
                        screenShotPath  = ADB.GetScreenshotPath();
                        smallScreenShot = BitmapOperation.CutImage(screenShotPath, new Point(Config.CutX, Config.CutY), new Size(Config.CutWidth, Config.CutHeight));
                        System.IO.File.Delete(screenShotPath);
                    }
                }
                catch (Exception ex)
                {
                    throw new ADBException("获取的屏幕截图无效!" + ex);
                }

                label_Message.Text = "正在识别题目信息";
                //调用API识别文字
                string recognizeResult = BaiDuOCR.Recognize(smallScreenShot);

                string[] recRes = Regex.Split(recognizeResult, "\r\n|\r|\n");
                //检查识别结果正确性
                CheckOCRResult(recRes);
                //显示识别结果

                int notEmptyIndex = recRes.Length - 1;
                while (String.IsNullOrEmpty(recRes[notEmptyIndex]))//忽略空行
                {
                    notEmptyIndex--;
                }

                textBox_AnswerC.Text = AnalyzeProblem.RemoveABC(recRes[notEmptyIndex--]);
                textBox_AnswerB.Text = AnalyzeProblem.RemoveABC(recRes[notEmptyIndex--]);
                textBox_AnswerA.Text = AnalyzeProblem.RemoveABC(recRes[notEmptyIndex--]);

                string problem = recRes[0];

                int dotP = problem.IndexOf('.');
                if (dotP != -1)
                {
                    problem = problem.Substring(dotP + 1, problem.Length - dotP - 1);
                }

                for (int i = 1; i <= notEmptyIndex; i++)
                {
                    problem += recRes[i];
                }

                textBox_Problem.Text = problem;
            }

            //浏览器跳转到搜索页面

            if (Config.RemoveUselessInfo)//移除无用信息
            {
                browserForm.Jump("http://www.baidu.com/s?wd=" + SearchEngine.UrlEncode(AnalyzeProblem.RemoveUselessInfo(textBox_Problem.Text)));
            }
            else
            {
                browserForm.Jump("http://www.baidu.com/s?wd=" + SearchEngine.UrlEncode(textBox_Problem.Text));
            }

            browserForm.Show();
            browserForm.WindowState = FormWindowState.Normal;

            label_Message.Text = "正在分析题目";
            //分析问题
            string[]      answerArr = new string[] { textBox_AnswerA.Text, textBox_AnswerB.Text, textBox_AnswerC.Text };
            AnalyzeResult aRes      = AnalyzeProblem.Analyze(textBox_Problem.Text, answerArr);

            char[] ans = new char[3] {
                'A', 'B', 'C'
            };
            label_Message.Text = "最有可能选择:" + ans[aRes.Index] + "项!" + answerArr[aRes.Index];
            if (aRes.Oppose)
            {
                label_Message.Text += "(包含否定词)";
            }

            label_Message.ForeColor   = Color.Green;
            label_AnalyzeA.ForeColor  = Color.DarkGreen;
            label_AnalyzeB.ForeColor  = Color.DarkGreen;
            label_AnalyzeC.ForeColor  = Color.DarkGreen;
            textBox_AnswerA.ForeColor = Color.Black;
            textBox_AnswerB.ForeColor = Color.Black;
            textBox_AnswerC.ForeColor = Color.Black;

            switch (aRes.Index)
            {
            case 0: label_AnalyzeA.ForeColor = Color.Red;
                textBox_AnswerA.ForeColor    = Color.Red;
                break;

            case 1: label_AnalyzeB.ForeColor = Color.Red;
                textBox_AnswerB.ForeColor    = Color.Red;
                break;

            case 2: label_AnalyzeC.ForeColor = Color.Red;
                textBox_AnswerC.ForeColor    = Color.Red;
                break;
            }

            //显示概率
            label_AnalyzeA.Text = "概率:" + aRes.Probability[0].ToString() + "%";
            label_AnalyzeB.Text = "概率:" + aRes.Probability[1].ToString() + "%";
            label_AnalyzeC.Text = "概率:" + aRes.Probability[2].ToString() + "%";
        }