public void testEmptyInput() { XmlNode testNode = StaticHelpers.getNode("<sentence/>"); this.mockBotTagHandler = new AIMLbot.AIMLTagHandlers.sentence(this.mockBot, this.mockUser, this.mockQuery, this.mockRequest, this.mockResult, testNode); this.mockQuery.InputStar.Clear(); Assert.AreEqual("", this.mockBotTagHandler.Transform()); }
public void testNonAtomicLower() { XmlNode testNode = StaticHelpers.getNode("<sentence>this is. a test to? see if this; works! ok</sentence>"); this.mockBotTagHandler = new AIMLbot.AIMLTagHandlers.sentence(this.mockBot, this.mockUser, this.mockQuery, this.mockRequest, this.mockResult, testNode); Assert.AreEqual("This is. A test to? See if this; Works! Ok", this.mockBotTagHandler.Transform()); }
public void testAtomic() { XmlNode testNode = StaticHelpers.getNode("<sentence/>"); this.mockBotTagHandler = new AIMLbot.AIMLTagHandlers.sentence(this.mockBot, this.mockUser, this.mockQuery, this.mockRequest, this.mockResult, testNode); this.mockQuery.InputStar.Insert(0, "THIS IS. A TEST TO? SEE IF THIS; WORKS! OK"); Assert.AreEqual("This is. A test to? See if this; Works! Ok", this.mockBotTagHandler.Transform()); }
public void testNonAtomicUpper() { XmlNode testNode = StaticHelpers.getNode("<sentence>THIS IS. A TEST TO? SEE IF THIS; WORKS! OK</sentence>"); this.mockBotTagHandler = new AIMLbot.AIMLTagHandlers.sentence(this.mockBot, this.mockUser, this.mockQuery, this.mockRequest, this.mockResult, testNode); Assert.AreEqual("This is. A test to? See if this; Works! Ok", this.mockBotTagHandler.Transform()); }
public void testAtomic() { XmlNode testNode = getNode("<sentence/>"); var mockBotTagHandler = new AIMLbot.AIMLTagHandlers.sentence(this.mockBot, this.mockUser, this.mockQuery, mockRequest, mockResult, testNode); this.mockQuery.InputStar.Insert(0, "THIS IS. A TEST TO? SEE IF THIS; WORKS! OK"); Assert.Equal("This is. A test to? See if this; Works! Ok", mockBotTagHandler.Transform()); }
protected override string ProcessChange() { if (this.templateNode.Name.ToLower() == "piglatin") { if (this.templateNode.InnerText.Length > 0) { StringBuilder result = new StringBuilder(); string[] words = this.templateNode.InnerText.ToLower().Split(" ".ToCharArray()); foreach (string word in words) { char[] letters = word.ToCharArray(); string consonantEnd = "ay"; string vowelEnd = "way"; string[] doubleConsonants = { "ph", "th", "ch", "pn", "sh", "st", "sp" }; string[] punctuation = { "\"", ".", "!", ";", "?", ")" }; Regex vowels = new Regex("[aeiou]", RegexOptions.IgnoreCase); Regex validChars = new Regex("[a-z]", RegexOptions.IgnoreCase); int locationOfFirstLetter = 0; bool isVowelEnding = false; string firstChar = ""; foreach (char character in letters) { if (vowels.IsMatch(character.ToString())) { isVowelEnding = true; firstChar = character.ToString(); break; } else if (validChars.IsMatch(character.ToString())) { isVowelEnding = false; string firstCharPair = word.Substring(locationOfFirstLetter, 2); foreach (string doubleCheck in doubleConsonants) { if (firstCharPair == doubleCheck) { firstChar = firstCharPair; } } if (firstChar.Length == 0) { firstChar = character.ToString(); } break; } locationOfFirstLetter++; } // stitch together if (locationOfFirstLetter > 0) { // start the word with any non-character chars (e.g. open brackets) result.Append(word.Substring(0, locationOfFirstLetter)); } int newStart = 0; if (isVowelEnding) { newStart = locationOfFirstLetter; } else { newStart = locationOfFirstLetter + firstChar.Length; } string tail = ""; if (isVowelEnding) { tail = vowelEnd; } else { tail = consonantEnd; } for (int i = newStart; i < letters.Length; i++) { string letter = letters[i].ToString(); bool isCharacter = true; foreach (string puntuationEnd in punctuation) { if (letter == puntuationEnd) { tail += letter; isCharacter = false; } } if (isCharacter) { result.Append(letter); } } if (!isVowelEnding) { result.Append(firstChar); } result.Append(tail + " "); } XmlNode dummySentence = getNode("<sentence>" + result.ToString().Trim() + "</sentence>"); AIMLbot.AIMLTagHandlers.sentence sentenceMaker = new AIMLbot.AIMLTagHandlers.sentence(this.bot, this.user, this.query, this.request, this.result, dummySentence); return(sentenceMaker.Transform()); } } return(string.Empty); }
protected override string ProcessChange() { if (this.templateNode.Name.ToLower() == "piglatin") { if (this.templateNode.InnerText.Length > 0) { StringBuilder result = new StringBuilder(); string[] words = this.templateNode.InnerText.ToLower().Split(" ".ToCharArray()); foreach (string word in words) { char[] letters = word.ToCharArray(); string consonantEnd = "ay"; string vowelEnd = "way"; string[] doubleConsonants = { "ph", "th", "ch", "pn", "sh", "st", "sp" }; string[] punctuation = { "\"", ".", "!", ";", "?", ")" }; Regex vowels = new Regex("[aeiou]", RegexOptions.IgnoreCase); Regex validChars = new Regex("[a-z]", RegexOptions.IgnoreCase); int locationOfFirstLetter = 0; bool isVowelEnding=false; string firstChar = ""; foreach (char character in letters) { if (vowels.IsMatch(character.ToString())) { isVowelEnding = true; firstChar=character.ToString(); break; } else if (validChars.IsMatch(character.ToString())) { isVowelEnding = false; string firstCharPair = word.Substring(locationOfFirstLetter, 2); foreach (string doubleCheck in doubleConsonants) { if (firstCharPair == doubleCheck) { firstChar = firstCharPair; } } if (firstChar.Length == 0) { firstChar = character.ToString(); } break; } locationOfFirstLetter++; } // stitch together if (locationOfFirstLetter > 0) { // start the word with any non-character chars (e.g. open brackets) result.Append(word.Substring(0, locationOfFirstLetter)); } int newStart = 0; if (isVowelEnding) { newStart = locationOfFirstLetter; } else { newStart = locationOfFirstLetter + firstChar.Length; } string tail = ""; if(isVowelEnding) { tail=vowelEnd; } else { tail=consonantEnd; } for(int i=newStart;i<letters.Length;i++) { string letter = letters[i].ToString(); bool isCharacter = true; foreach(string puntuationEnd in punctuation) { if(letter==puntuationEnd) { tail+=letter; isCharacter=false; } } if(isCharacter) { result.Append(letter); } } if (!isVowelEnding) { result.Append(firstChar); } result.Append(tail+" "); } XmlNode dummySentence = getNode("<sentence>" + result.ToString().Trim() + "</sentence>"); AIMLbot.AIMLTagHandlers.sentence sentenceMaker = new AIMLbot.AIMLTagHandlers.sentence(this.bot, this.user, this.query, this.request, this.result, dummySentence); return sentenceMaker.Transform(); } } return string.Empty; }