示例#1
0
 public Conversation(Memory memory, ChatbotConfig config, [Named("plugin")] Logger log, PlaceholderHandler ph)
 {
     this.memory              = memory;
     currentMoodValue         = .5f;
     negativeWordMatchPattern = new Regex(string.Join("|", config.NegativeWords), RegexOptions.Compiled | RegexOptions.IgnoreCase);
     positiveWordMatchPattern = new Regex(string.Join("|", config.PositiveWords), RegexOptions.Compiled | RegexOptions.IgnoreCase);
     this.log           = log;
     random             = new Random();
     placeholderHandler = ph;
 }
示例#2
0
        private static void SubstituteBotNicks(ChatbotConfig cfg, List <string> wordPool)
        {
            List <string> replacements = new List <string>();

            for (int i = 0; i < wordPool.Count; i++)
            {
                var keyword = wordPool[i];
                // if we find the occurence of bot nick placeholder,
                // remove it from the list and prepare replacement versions for each available bot nick.
                if (Regex.IsMatch(keyword, "({bot name})"))
                {
                    replacements.AddRange(cfg.BotNicks.Select(t => Regex.Replace(keyword, "({bot name})", t)));
                    wordPool.RemoveAt(i--);
                }
            }

            // then put in the replacement values that contain the concrete (ro)bot nicks
            wordPool.AddRange(replacements);
        }
示例#3
0
        public static Dictionary <Mood, List <CompiledRule> > CompileRules(IEnumerable <RawResponseNode> rawNodeList, ChatbotConfig cfg)
        {
            Dictionary <Mood, List <CompiledRule> > sortedResponses = new Dictionary <Mood, List <CompiledRule> > {
                { Mood.Neutral, new List <CompiledRule>() },
                { Mood.Friendly, new List <CompiledRule>() },
                { Mood.Angry, new List <CompiledRule>() }
            };

            // this will replace bot name placeholder with a range of actual bot nicks.
            // will work not so great if there is stuff like
            foreach (var node in rawNodeList)
            {
                if (node.PrimaryWordPool != null)
                {
                    SubstituteBotNicks(cfg, node.PrimaryWordPool);
                }

                if (node.SecondaryWordPool != null)
                {
                    SubstituteBotNicks(cfg, node.SecondaryWordPool);
                }

                var neutral = CompiledRule.CompileForMood(Mood.Neutral, node, cfg);
                if (neutral != null)
                {
                    sortedResponses[Mood.Neutral].Add(neutral);
                }

                var friendly = CompiledRule.CompileForMood(Mood.Friendly, node, cfg);
                if (friendly != null)
                {
                    sortedResponses[Mood.Friendly].Add(friendly);
                }

                var angry = CompiledRule.CompileForMood(Mood.Angry, node, cfg);
                if (angry != null)
                {
                    sortedResponses[Mood.Angry].Add(angry);
                }
            }

            return(sortedResponses);
        }
 public DefaultPlaceholderProvider(ChatbotConfig cfg)
 {
     botCfg = cfg;
 }
示例#5
0
 public PlaceholderHandler(ChatbotConfig cfg)
 {
     botCfg = cfg;
 }
示例#6
0
 public Memory(ChatbotConfig cfg, ChatbotRuleConfig rules)
 {
     responses = RuleCompiler.CompileRules(rules.responseRules, cfg);
 }