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); } } } }
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()); }
static string AskQuestion() { activeQuestion = QnAData.rng.Next(QnAData.GetQuestionsCount()); return(QnAData.GetQuestion(activeQuestion)); }
public static string StartConversation() { return(QnAData.DefaultStart() + Environment.NewLine + AskQuestion()); }