예제 #1
0
 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());
 }
예제 #2
0
        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());
        }
예제 #3
0
 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());
 }
예제 #4
0
        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());
        }
예제 #5
0
        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());
        }
예제 #6
0
        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());
        }
예제 #7
0
        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);
        }
예제 #8
0
 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());
 }
예제 #9
0
        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;
        }