示例#1
0
 public static void ReadQnAFromFile()
 {
     QnAData.CreateQnAList();
     string[] lines = System.IO.File.ReadAllLines(@"./QnAData/QnA.txt", Encoding.Default);
     foreach (string line in lines)
     {
         if (line[line.Length - 1] == '?')
         {
             QnAData.AddQuestion(line);
         }
         else
         {
             if (line[line.Length - 1] == '.')
             {
                 QnAData.AddAnswerToLastQuestion(line);
             }
             else
             {
                 QnAData.AddKeywordsToLastQuestion(line);
             }
         }
     }
 }
示例#2
0
        static string Answer(string message)
        {
            string answer = null;

            char[] arr = message.ToCharArray();

            arr = Array.FindAll <char>(arr, (c => (char.IsLetterOrDigit(c) ||
                                                   char.IsWhiteSpace(c))));
            //                                || c == '-')));
            message = new string(arr);
            message = message.ToLower();
            var words = message.Split(' ');

            for (int i = 0; i < words.Length; i++)
            {
                answer = QnAData.GetAnswer(activeQuestion, words[i]);
                if (answer != null)
                {
                    return(answer);
                }
            }
            return(QnAData.DefaultAnswer());
        }
示例#3
0
 static string AskQuestion()
 {
     activeQuestion = QnAData.rng.Next(QnAData.GetQuestionsCount());
     return(QnAData.GetQuestion(activeQuestion));
 }
示例#4
0
 public static string StartConversation()
 {
     return(QnAData.DefaultStart() + Environment.NewLine + AskQuestion());
 }