public string Parse(string Sentence) { string[] words = Sentence.Split(' '); int i = 0; int wordPos = 0; for (i = 0; i < words.Length; i++) { //remove punctuation here or earlier wordPos = WordPos(words[i]); if ( wordPos != -1 && i < (words.Length-1) ) { Vocabulary[wordPos].AddNewNext(words[i + 1]); } else if ( wordPos == -1 && i < (words.Length-1) ) { Word newWord = new Word(words[i], words[i+1]); Vocabulary.Add(newWord); } else if (wordPos == -1) { Word newWord = new Word(words[i]); Vocabulary.Add(newWord); } } return (Answer(words)); }
Random ran = new Random(); //This is for use with ChooseWord. It has to be outside because otherwise it is unreliable #endregion Fields #region Methods public string Parse(string Sentence) { bool question = false; string[] words = new string[0]; int i = 0; int wordPos = 0; StringReader letterchecker; if (Sentence.IndexOf("?") != -1) { question = true; } Sentence = RemovePunctuation(Sentence); words = Sentence.Split(' '); for (i = 0; i < words.Length; i++) { letterchecker = new StringReader(words[i]); char[] firstletter = new char[1]; letterchecker.Read(firstletter, 0, 1); bool upper = false; if (Char.IsUpper(firstletter[0])) { upper = true; words[i] = words[i].ToLower(); } words[i] = words[i].ToLower(); wordPos = WordPos(words[i]); if ( wordPos != -1 && i < (words.Length-1) ) { Vocabulary[wordPos].AddNewNext(words[i + 1]); if (i == 0) { Vocabulary[wordPos].start = true; } if (question) { Vocabulary[wordPos].question = true; } if (upper && i > 0) { Vocabulary[wordPos].upper = true; } } else if ( wordPos == -1 && i < (words.Length-1) ) { Word newWord = new Word(words[i], words[i+1]); if (i == 0) { newWord.start = true; } if (question == true) { newWord.question = true; } if (upper && i > 0) { Vocabulary[wordPos].upper = true; } Vocabulary.Add(newWord); } else if (wordPos == -1) { Word newWord = new Word(words[i]); if (i == 0) { newWord.start = true; } if (question == true) { newWord.question = true; } if (upper && i > 0) { Vocabulary[wordPos].upper = true; } Vocabulary.Add(newWord); } } return (Answer(words, question)); }
Random ran = new Random(); //This is for use with ChooseWord. It has to be outside because otherwise it is unreliable #endregion Fields #region Methods public string Parse(string Sentence) { bool question = false; string[] words = new string[0]; int i = 0; int wordPos = 0; if (Sentence.IndexOf("?") != -1) { question = true; } Sentence = RemovePunctuation(Sentence); words = Sentence.Split(' '); for (i = 0; i < words.Length; i++)//loop for sanitising input and recording capitals { words[i] = words[i].ToLower();//Add a way of recording capitalisation before here. } for (i = 0; i < words.Length; i++) { wordPos = WordPos(words[i]); if ( wordPos != -1 && i < (words.Length-1) ) { Vocabulary[wordPos].AddNewNext(words[i + 1]); if (i == 0) { Vocabulary[wordPos].start = true; } if (question == true) { Vocabulary[wordPos].question = true; } } else if ( wordPos == -1 && i < (words.Length-1) ) { Word newWord = new Word(words[i], words[i+1]); if (i == 0) { newWord.start = true; } if (question == true) { newWord.question = true; } Vocabulary.Add(newWord); } else if (wordPos == -1) { Word newWord = new Word(words[i]); if (i == 0) { newWord.start = true; } if (question == true) { newWord.question = true; } Vocabulary.Add(newWord); } } return (Answer(words, question)); }