public async Task <string> Create(SearchOption option, string searchWord)
        {
            ISearchOp searchOp = null;

            switch (option)
            {
            case SearchOption.Bing:
            {
                searchOp = new BingSearch();
                searchOp.BuildSearchUrl(searchWord);
                return(await searchOp.GetSearchResult(searchWord));
            }

            case SearchOption.Google:
            {
                searchOp = new GoogleSearch();
                searchOp.BuildSearchUrl(searchWord);
                return(await searchOp.GetSearchResult(searchWord));
            }

            case SearchOption.DuckDuckgo:
            {
                searchOp = new DuckDuckgoSearch();
                searchOp.BuildSearchUrl(searchWord);
                return(await searchOp.GetSearchResult(searchWord));
            }

            case SearchOption.Yandex:
            {
                searchOp = new YandexSearch();
                searchOp.BuildSearchUrl(searchWord);
                return(await searchOp.GetSearchResult(searchWord));
            }
            }

            return(null);
        }
Exemplo n.º 2
0
        static int gameCode = 0; // Which game? 0 - 冲顶大会 1 - 芝士超人 2 - 百万英雄 3 - zhihu

        static int Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
#if DEBUG
            gameCode = 1;
            string imageFilePath = @"D:\Workspace\AnswerApp\screenshot13-13.png";
#else
            gameCode = int.Parse(args[1]);
            string imageFilePath = args[0];
#endif

            string   question = string.Empty;
            string[] option;

            if (gameCode == 3) // zhihu
            {
                ZhihuImageProcess(imageFilePath, out question, out option);
            }
            else
            {
                Basic3ChoicesImageProcess(imageFilePath, out question, out option);
            }

            Console.WriteLine("Question: {0}", question);
            Console.WriteLine("A: {0}", option[0]);
            Console.WriteLine("B: {0}", option[1]);
            Console.WriteLine("C: {0}", option[2]);
            if (gameCode == 3)
            {
                Console.WriteLine("D: {0}", option[3]);
            }

            bool noflag = false;
            if (question.Contains("不"))
            {
                noflag   = true;
                question = question.Replace("不", "");
                Console.WriteLine("不字反转启动");
            }

            //string keyword = getKeyword(question);
            //Console.WriteLine("Got keyword {0}", keyword);
            double[] rate = new double[choices];

            var searcher = new BingSearch();

            // show search result
            if (args.Length >= 3)
            {
                var count = searcher.SearchCounterAsync(question, true).Result;
            }

            var numerators   = new Task <double> [choices];
            var denominators = new Task <double> [choices];

            for (int i = 0; i < choices; i++)
            {
                numerators[i]   = searcher.SearchCounterAsync(question + " " + "\"" + option[i] + "\"");
                denominators[i] = searcher.SearchCounterAsync("\"" + option[i] + "\"");
            }

            for (int i = 0; i < choices; i++)
            {
                double a = numerators[i].Result;
                double b = denominators[i].Result;

                if (b < 1)
                {
                    b = 100000000000;
                }

                rate[i] = a / b;
                Console.WriteLine("Rating for choice {0}: {1} / {2} = {3}", i + 1, a, b, rate[i]);
            }

            int ans = noflag ? Utils.GetSmallestIndex(rate) : Utils.GetBiggestIndex(rate);
            Console.WriteLine("推荐答案 {0}: {1}", Convert.ToChar('A' + ans), option[ans]);
            return(ans);
        }