Exemplo n.º 1
0
 public void Setup()
 {
     _paragraph      = TestData.Wiki;
     _questions      = TestData.Questions;
     _correctAnswers = TestData.CorrectAnswers;
     _answers        = TestData.Answers;
     _answerFinder   = new AnswerFinder();
     _contentIndex   = new ContentIndexBuilder().Build(_paragraph);
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            AnswerFinder        answerFinder = new AnswerFinder();
            String              question     = Console.ReadLine();
            String              subject      = Console.ReadLine();
            List <QuestionInfo> results      = answerFinder.FindAnswers(question, subject);

            foreach (QuestionInfo questionInfo in results)
            {
                Console.WriteLine("******");
                Console.WriteLine(questionInfo.Question);
                Console.WriteLine(questionInfo.Answer);
            }

            Console.WriteLine("Done");
        }
Exemplo n.º 3
0
 public SolverController(ApplicationDbContext applicationDbContext)
 {
     _answerFinder = new AnswerFinder();
     dbContext     = applicationDbContext;
     _logger       = new Log();
 }
Exemplo n.º 4
0
        static string FigureOutRightAnswer(string question, string a, string b, string c)
        {
            var questionForQuery = question;

            var negative = false;

            if (question.ToLower().Contains(" not "))
            {
                negative         = true;
                questionForQuery = question.Replace("not", "");
            }

            //quotes around cases - all words in case should be present
            var queryA = $"{questionForQuery} \"{a}\"";
            var queryB = $"{questionForQuery} \"{b}\"";
            var queryC = $"{questionForQuery} \"{c}\"";

            //no quotes
            //var queryA = $"{questionForQuery} {a}";
            //var queryB = $"{questionForQuery} {b}";
            //var queryC = $"{questionForQuery} {c}";

//            var searchClient = new GoogleSearchClient();
//
//            var taskD = Task.Run<Answer>(() => AnswerFinder.FindAnswer(question, a, b, c));
//            var taskA = Task.Run<long>(() => searchClient.RunSearch(queryA));
//            var taskB = Task.Run<long>(() => searchClient.RunSearch(queryB));
//            var taskC = Task.Run<long>(() => searchClient.RunSearch(queryC));


            var searchClient = new BingSearchClient();

            var taskD = Task.Run <Answer>(() => AnswerFinder.FindAnswer(question, a, b, c));
            var taskA = Task.Run <long>(() => searchClient.TotalSearchResults(queryA));
            var taskB = Task.Run <long>(() => searchClient.TotalSearchResults(queryB));
            var taskC = Task.Run <long>(() => searchClient.TotalSearchResults(queryC));

            var results = new Dictionary <string, long>();

            results.Add($"1. {a}", taskA.Result);
            results.Add($"2. {b}", taskB.Result);
            results.Add($"3. {c}", taskC.Result);

            var answer = taskD.Result;

            KeyValuePair <string, long> winner;

            if (answer.percentSure > 0)
            {
                if (answer.CorrectAnswer == 1)
                {
                    winner = results.Single(x => x.Key.StartsWith("1."));
                }
                else if (answer.CorrectAnswer == 2)
                {
                    winner = results.Single(x => x.Key.StartsWith("2."));
                }
                else if (answer.CorrectAnswer == 3)
                {
                    winner = results.Single(x => x.Key.StartsWith("3."));
                }
            }

            else
            {
                winner = negative
                ? results.OrderByDescending(res => res.Value).LastOrDefault()
                : results.OrderByDescending(res => res.Value).FirstOrDefault();
            }

            var winnerString = winner.Key;

            return(winnerString);

            //For testing
            //Console.WriteLine(a);
            //Console.WriteLine(b);
            //Console.WriteLine(c)
        }