public void testAlphaNumericCharactersWithSpaces()
 {
     this.mockStripper = new AIMLbot.Normalize.StripIllegalCharacters(this.mockBot);
     string testString = "01234567 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz";
     this.mockStripper.InputString = testString;
     Assert.AreEqual(testString, this.mockStripper.Transform());
 }
        public void testNonAlphaNumericBecomeSpaces()
        {
            string testString = "!\"£$%^&*()-+'";

            this.mockStripper = new AIMLbot.Normalize.StripIllegalCharacters(this.mockBot, testString);
            Assert.AreEqual("             ", this.mockStripper.Transform());
        }
        public void testAlphaNumericCharactersWithSpaces()
        {
            this.mockStripper = new AIMLbot.Normalize.StripIllegalCharacters(this.mockBot);
            string testString = "01234567 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz";

            this.mockStripper.InputString = testString;
            Assert.AreEqual(testString, this.mockStripper.Transform());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Given an input, provide a normalized output
        /// </summary>
        /// <param name="input">The string to be normalized</param>
        /// <param name="isUserInput">True if the string being normalized is part of the user input path -
        /// flags that we need to normalize out * and _ chars</param>
        /// <returns>The normalized string</returns>
        public string Normalize(string input, bool isUserInput)
        {
            StringBuilder result = new StringBuilder();

            // objects for normalization of the input
            Normalize.ApplySubstitutions     substitutor = new AIMLbot.Normalize.ApplySubstitutions(this.bot);
            Normalize.StripIllegalCharacters stripper    = new AIMLbot.Normalize.StripIllegalCharacters(this.bot);

            string substitutedInput = substitutor.Transform(input);

            // split the pattern into it's component words
            string[] substitutedWords = substitutedInput.Split(" \r\n\t".ToCharArray());

            // Normalize all words unless they're the AIML wildcards "*" and "_" during AIML loading
            foreach (string word in substitutedWords)
            {
                string normalizedWord;
                if (isUserInput)
                {
                    normalizedWord = stripper.Transform(word);
                }
                else
                {
                    if ((word == "*") || (word == "_"))
                    {
                        normalizedWord = word;
                    }
                    else
                    {
                        normalizedWord = stripper.Transform(word);
                    }
                }
                //result.Append(normalizedWord.Trim() + " ");
                result.Append(normalizedWord.Trim());//中文
            }

            //return result.ToString().Replace("  ", " "); // make sure the whitespace is neat
            return(result.ToString().Trim()); //中文
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Given an input, provide a normalized output
        /// </summary>
        /// <param name="input">The string to be normalized</param>
        /// <param name="isUserInput">True if the string being normalized is part of the user input path - 
        /// flags that we need to normalize out * and _ chars</param>
        /// <returns>The normalized string</returns>
        public string Normalize(string input, bool isUserInput)
        {
            StringBuilder result = new StringBuilder();

            // objects for normalization of the input
            Normalize.ApplySubstitutions substitutor = new AIMLbot.Normalize.ApplySubstitutions(this.bot);
            Normalize.StripIllegalCharacters stripper = new AIMLbot.Normalize.StripIllegalCharacters(this.bot);

            string substitutedInput = substitutor.Transform(input);
            // split the pattern into it's component words
            string[] substitutedWords = substitutedInput.Split(" \r\n\t".ToCharArray());

            // Normalize all words unless they're the AIML wildcards "*" and "_" during AIML loading
            foreach (string word in substitutedWords)
            {
                string normalizedWord;
                if (isUserInput)
                {
                    normalizedWord = stripper.Transform(word);
                }
                else
                {
                    if ((word == "*") || (word == "_"))
                    {
                        normalizedWord = word;
                    }
                    else
                    {
                        normalizedWord = stripper.Transform(word);
                    }
                }
                result.Append(normalizedWord.Trim() + " ");
            }

            return result.ToString().Replace("  "," "); // make sure the whitespace is neat
        }
 public void testWithEmptyString()
 {
     this.mockStripper = new AIMLbot.Normalize.StripIllegalCharacters(this.mockBot, "");
     Assert.AreEqual("", this.mockStripper.Transform());
 }
 public void testNonAlphaNumericBecomeSpaces()
 {
     string testString="!\"£$%^&*()-+'";
     this.mockStripper = new AIMLbot.Normalize.StripIllegalCharacters(this.mockBot, testString);
     Assert.AreEqual("             ", this.mockStripper.Transform());
 }
 public void testWithEmptyString()
 {
     this.mockStripper = new AIMLbot.Normalize.StripIllegalCharacters(this.mockBot, "");
     Assert.AreEqual("", this.mockStripper.Transform());
 }