/// <summary> /// Create a new QuestionTemplate object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="regex">Initial value of the Regex property.</param> public static QuestionTemplate CreateQuestionTemplate(global::System.Int64 id, global::System.String regex) { QuestionTemplate questionTemplate = new QuestionTemplate(); questionTemplate.Id = id; questionTemplate.Regex = regex; return questionTemplate; }
private void IniQuestionTemplate() { w("Initialling question template..."); using (DataContainer c = new DataContainer()) { QuestionTemplate q1 = new QuestionTemplate(); q1.Regex = @"(今天|现在)几号"; c.AddToQuestionTemplate(q1); AnswerTemplate a1 = new AnswerTemplate(); a1.Answer = "{nowdate}"; c.AddToAnswerTemplate(a1); AnswerTemplate a11 = new AnswerTemplate(); a11.Answer = "今天应该是{nowdate}"; c.AddToAnswerTemplate(a11); QuestionTemplate q2 = new QuestionTemplate(); q2.Regex = @"(现在)?几点"; c.AddToQuestionTemplate(q2); AnswerTemplate a2 = new AnswerTemplate(); a2.Answer = "{nowtime}"; c.AddToAnswerTemplate(a2); AnswerTemplate a21 = new AnswerTemplate(); a21.Answer = "差不多{nowtime}的样子"; c.AddToAnswerTemplate(a21); q1.AnswerTemplate.Add(a1); q1.AnswerTemplate.Add(a11); q2.AnswerTemplate.Add(a2); q2.AnswerTemplate.Add(a21); c.SaveChanges(); } w("Initialling question template complete."); }
/// <summary> /// Deprecated Method for adding a new object to the QuestionTemplate EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToQuestionTemplate(QuestionTemplate questionTemplate) { base.AddObject("QuestionTemplate", questionTemplate); }
private static void Learning() { while (true) { string input = Console.ReadLine().Trim(); if (string.IsNullOrEmpty(input)) { continue; } using (DataContainer c = new DataContainer()) { var temps = c.QuestionTemplate.ToList(); QuestionTemplate findedQuestion = null; foreach (QuestionTemplate temp in temps) { if (Regex.IsMatch(input, temp.Regex)) { findedQuestion = temp; } } if (findedQuestion == null) { Console.WriteLine("answer:"); string str_a = Console.ReadLine(); List<AnswerTemplate> OtherAnswers = new List<AnswerTemplate>(); Console.WriteLine("onther answer:"); string str_other_answer = Console.ReadLine().Trim(); while (string.IsNullOrEmpty(str_other_answer) == false) { AnswerTemplate ans = new AnswerTemplate(); ans.Answer = str_other_answer; c.AddToAnswerTemplate(ans); OtherAnswers.Add(ans); str_other_answer = Console.ReadLine().Trim(); } Console.WriteLine("Possible questrion:"); string str_reg = Console.ReadLine(); QuestionTemplate q = new QuestionTemplate(); if (string.IsNullOrEmpty(str_reg)) { q.Regex = input; } else { q.Regex = str_reg; } c.AddToQuestionTemplate(q); AnswerTemplate a = new AnswerTemplate(); a.Answer = str_a; a.QuestionTemplate = q; c.AddToAnswerTemplate(a); foreach (AnswerTemplate answerTemplate in OtherAnswers) { answerTemplate.QuestionTemplate = q; } c.SaveChanges(); Console.WriteLine("ok ,I got it."); } else { Console.WriteLine(WordsProcess.ProcessAll(findedQuestion.AnswerTemplate.OrderBy(p => Guid.NewGuid()).First().Answer)); List<AnswerTemplate> OtherAnswers = new List<AnswerTemplate>(); Console.WriteLine("onther answer:"); string str_other_answer = Console.ReadLine().Trim(); while (string.IsNullOrEmpty(str_other_answer) == false) { AnswerTemplate ans = new AnswerTemplate(); ans.Answer = str_other_answer; c.AddToAnswerTemplate(ans); OtherAnswers.Add(ans); ans.QuestionTemplate = findedQuestion; str_other_answer = Console.ReadLine().Trim(); } c.SaveChanges(); } } } }