Beispiel #1
0
        /// <summary>
        /// Static helper that applies replacements from the passed dictionary object to the
        /// target string
        /// </summary>
        /// <param name="bot">The bot for whom this is being processed</param>
        /// <param name="dictionary">The dictionary containing the substitutions</param>
        /// <param name="target">the target string to which the substitutions are to be applied</param>
        /// <returns>The processed string</returns>
        public static string Substitute(AIMLbot.Bot bot, AIMLbot.Utils.SettingsDictionary dictionary, string target)
        {
            string result = target;//MakeCaseInsensitive.TransformInput(target);

            foreach (string pattern in dictionary.SettingNames)
            {
                string p2 = ApplySubstitutions.makeRegexSafe(pattern);
                //string match = "\\b" + @p2.Trim() + "\\b";
                string match       = @p2;
                string replacement = dictionary.grabSetting(pattern);
                if (replacement.StartsWith(" "))
                {
                    replacement = " ||" + replacement.TrimStart();
                }
                else
                {
                    replacement = "||" + replacement;
                }
                if (replacement.EndsWith(" "))
                {
                    replacement = replacement.TrimEnd() + "|| ";
                }
                else
                {
                    replacement = replacement + "||";
                }
                result = Regex.Replace(result, match, replacement, RegexOptions.IgnoreCase);
            }

            return(result.Replace("||", ""));
        }
Beispiel #2
0
        /// <summary>
        /// Static helper that applies replacements from the passed dictionary object to the
        /// target string
        /// </summary>
        /// <param name="bot">The bot for whom this is being processed</param>
        /// <param name="dictionary">The dictionary containing the substitutions</param>
        /// <param name="target">the target string to which the substitutions are to be applied</param>
        /// <returns>The processed string</returns>
        public static string Substitute(AIMLbot.Bot bot, AIMLbot.Utils.SettingsDictionary dictionary, string target)
        {
            string marker = ApplySubstitutions.getMarker(5);
            string result = target;

            foreach (string pattern in dictionary.SettingNames)
            {
                string p2      = ApplySubstitutions.makeRegexSafe(pattern);
                string valueP2 = dictionary.grabSetting(pattern).Trim();

                Regex regPattern = new Regex(p2, RegexOptions.Singleline | RegexOptions.IgnoreCase);
                Match match      = regPattern.Match(result);
                if (match.Success)
                {
                    string match1 = p2.TrimEnd().TrimStart();
                    if (!String.IsNullOrEmpty(match1))
                    {
                        string replacement = marker + dictionary.grabSetting(pattern) + marker;
                        result = Regex.Replace(result, match1, replacement, RegexOptions.IgnoreCase);
                    }
                }
                //result = Regex.Replace(result, p2, valueP2, RegexOptions.IgnoreCase);
                //string match = "\\b"[email protected]().Replace(" ","\\s*")+"\\b";
                //string match = p2.TrimEnd().TrimStart();
                //string replacement = marker+dictionary.grabSetting(pattern).Trim()+marker;
                //result = Regex.Replace(result, match, replacement, RegexOptions.IgnoreCase);
            }

            return(result.Replace(marker, ""));
            //return result;
        }
Beispiel #3
0
        protected override string ProcessChange()
        {
            string result = this.inputString;//MakeCaseInsensitive.TransformInput(this.inputString);

            foreach (string pattern in this.bot.Substitutions.SettingNames)
            {
                string p2 = ApplySubstitutions.makeRegexSafe(pattern);
                //string match = "\\b" + p2.Trim() + "\\b";
                string match       = @p2;
                string replacement = this.bot.Substitutions.grabSetting(pattern);
                if (replacement.StartsWith(" "))
                {
                    replacement = " ||" + replacement.TrimStart();
                }
                else
                {
                    replacement = "||" + replacement;
                }
                if (replacement.EndsWith(" "))
                {
                    replacement = replacement.TrimEnd() + "|| ";
                }
                else
                {
                    replacement = replacement + "||";
                }
                result = Regex.Replace(result, match, replacement, RegexOptions.IgnoreCase);
            }

            return(result.Replace("||", ""));
        }
Beispiel #4
0
 public void testWithNonMatchingMultiWordSubstitutions()
 {
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, "you r sweet");
     this.mockBot.Substitutions.loadSettings(this.substitutions);
     Assert.AreEqual("you are sweet", this.mockSubstitutor.Transform());
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, "your sweet");
     Assert.AreEqual("your sweet", this.mockSubstitutor.Transform());
 }
 public void testWithNonMatchingMultiWordSubstitutions()
 {
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, "you r sweet");
     this.mockBot.Substitutions.loadSettings(this.substitutions);
     Assert.AreEqual("you are sweet", this.mockSubstitutor.Transform());
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, "your sweet");
     Assert.AreEqual("your sweet", this.mockSubstitutor.Transform());
 }
        // Token: 0x06000043 RID: 67 RVA: 0x00003454 File Offset: 0x00002454
        public static string Substitute(Bot bot, SettingsDictionary dictionary, string target)
        {
            string marker = ApplySubstitutions.getMarker(5);
            string text   = target;

            foreach (string text2 in dictionary.SettingNames)
            {
                string text3       = ApplySubstitutions.makeRegexSafe(text2);
                string pattern     = "\\b" + text3.TrimEnd(new char[0]).TrimStart(new char[0]) + "\\b";
                string replacement = marker + dictionary.grabSetting(text2).Trim() + marker;
                text = Regex.Replace(text, pattern, replacement, RegexOptions.IgnoreCase);
            }
            return(text.Replace(marker, ""));
        }
        /// <summary>
        /// Static helper that applies replacements from the passed dictionary object to the
        /// target string
        /// </summary>
        /// <param name="bot">The bot for whom this is being processed</param>
        /// <param name="dictionary">The dictionary containing the substitutions</param>
        /// <param name="target">the target string to which the substitutions are to be applied</param>
        /// <returns>The processed string</returns>
        public static string Substitute(AIMLbot.Bot bot, AIMLbot.Utils.SettingsDictionary dictionary, string target)
        {
            string marker = ApplySubstitutions.getMarker(5);
            string result = target;

            foreach (string pattern in dictionary.SettingNames)
            {
                string p2 = ApplySubstitutions.makeRegexSafe(pattern);
                //string match = "\\b"[email protected]().Replace(" ","\\s*")+"\\b";
                string match       = "\\b" + p2.TrimEnd().TrimStart() + "\\b";
                string replacement = marker + dictionary.grabSetting(pattern).Trim() + marker;
                result = Regex.Replace(result, match, replacement, RegexOptions.IgnoreCase);
            }

            return(result.Replace(marker, ""));
        }
Beispiel #8
0
 public void testWithMultiWordSubstitutions()
 {
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, "How R U");
     this.mockBot.Substitutions.loadSettings(this.substitutions);
     Assert.AreEqual("How are you", this.mockSubstitutor.Transform());
 }
Beispiel #9
0
 public void testPartialMatch()
 {
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, "My favourite things");
     this.mockBot.Substitutions.loadSettings(this.substitutions);
     Assert.AreEqual("My favourite things", this.mockSubstitutor.Transform());
 }
Beispiel #10
0
 public void testNoMatchData()
 {
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, "No substitutions here");
     this.mockBot.Substitutions.loadSettings(this.substitutions);
     Assert.AreEqual("No substitutions here", this.mockSubstitutor.Transform());
 }
Beispiel #11
0
 public void testWithGoodData()
 {
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, " this is a test ");
     this.mockBot.Substitutions.loadSettings(this.substitutions);
     Assert.AreEqual(" the test works great ", this.mockSubstitutor.Transform());
 }
 protected override string ProcessChange()
 {
     return(ApplySubstitutions.Substitute(this.bot, this.bot.Substitutions, this.inputString));
 }
 public void testWithMultiWordSubstitutions()
 {
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, "How R U");
     this.mockBot.Substitutions.loadSettings(this.substitutions);
     Assert.AreEqual("How are you", this.mockSubstitutor.Transform());
 }
 public void testPartialMatch()
 {
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, "My favourite things");
     this.mockBot.Substitutions.loadSettings(this.substitutions);
     Assert.AreEqual("My favourite things", this.mockSubstitutor.Transform());
 }
 public void testNoMatchData()
 {
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, "No substitutions here");
     this.mockBot.Substitutions.loadSettings(this.substitutions);
     Assert.AreEqual("No substitutions here", this.mockSubstitutor.Transform());
 }
 public void testWithGoodData()
 {
     this.mockSubstitutor = new ApplySubstitutions(this.mockBot, " this is a test ");
     this.mockBot.Substitutions.loadSettings(this.substitutions);
     Assert.AreEqual(" the test works great ", this.mockSubstitutor.Transform());
 }