コード例 #1
0
        private QuestionAndAnswer[] GetAnswers(Message message)
        {
            QuestionAndAnswer[] answers;
            if (message.Payload != null)
            {
                var          question      = (string)JsonConvert.DeserializeObject <dynamic>(message.Payload).Question;
                var          answer        = questionAndAnswerRepository.FindByQuestion(question);
                const string unknownAnswer = "Мне не удалось найти этот ответ.\nЧто-то пошло не так :(";
                answers = new[] { answer ?? new QuestionAndAnswer {
                                      Answer = unknownAnswer
                                  } };
            }
            else
            {
                var answer = questionAndAnswerRepository.FindByQuestion(message.Text);
                if (answer != null)
                {
                    answers = new[] { answer }
                }
                ;
                else
                {
                    var answersOnly = wordAndAnswerRepository.FindSeveralByPhrase(message.Text.ToLower()).ToArray();
                    answers = questionAndAnswerRepository.FindSeveralByAnswers(answersOnly).ToArray();
                }
            }

            return(answers);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var connectionString = "Server=localhost;Port=3306;User=u1090_113default;Password=E51wd#2i;Database=u1090113_default;";

            var db     = new MySqlDataBase(connectionString);
            var parser = new CSVParser("csvData.csv",
                                       new QuestionAndAnswerRepository(db), new WordAndAnswerRepository(db));
            // parser.Parse();
            var qr      = new QuestionAndAnswerRepository(db);
            var answers = new WordAndAnswerRepository(db).FindSeveralByPhrase("что курсовая когда зачем баллы");

            foreach (var answer in qr.FindSeveralByAnswers(answers))
            {
                Console.WriteLine(answer.Question);
            }
        }