示例#1
0
        public static List <Reply> findBestReply(ReplyList input)
        {
            float        weight = -1;
            List <Reply> list   = new List <Reply>();

            foreach (Reply R in input.list)
            {
                //Check equal or greater weights
                if (weight == R.weight)
                {
                    list.Add(R);
                }
                if (weight < R.weight)
                {
                    list.Clear();
                    list.Add(R);
                    weight = R.weight;
                }
            }

            return(list);
        }
示例#2
0
        private Reply PatternMatchReply(string input)
        {
            ReplyList allReplyList = new ReplyList();

            if (CorpseData.Length == 0)
            {
                return(new Reply());
            }
            input = removePunctuations(input);
            foreach (string token in input.Split(' '))
            {
                int index = CorpseData[0].FindIndex(X => X == token);
                if (index == -1)
                {
                    continue;
                }
                allReplyList.parseReplyList(CorpseData[1][index].Split(','), CorpseData[2][index].Split(','), Type);
            }
            if (allReplyList.isEmpty)
            {
                return(null);
            }
            List <Reply> Replies = ReplyList.findBestReply(allReplyList);

            if (Replies.Count == 0)
            {
                return(null);
            }
            else if (Replies.Count == 1)
            {
                if (LastReply == "")
                {
                    return(Replies[0]);
                }
                Reply R = Replies[0];
                if (R.reply == LastReply && Type != SystemType.COMMAND)
                {
                    if (WarningCount >= 2 && !isTrainingModeEnabled)
                    {
                        WarningCount = 0;
                        return(new Reply("Why do you keep asking me the same question ?", float.Parse("0.4")));
                    }
                    else
                    {
                        WarningCount++;
                        return(R);
                    }
                }
                else
                {
                    return(R);
                }
            }
            else
            {
                foreach (Reply R in Replies)
                {
                    if (UsedReplies.FindIndex(UR => UR == R.reply) == -1)
                    {
                        UsedReplies.Add(R.reply);
                        return(R);
                    }
                }
                foreach (Reply R in Replies)
                {
                    UsedReplies.Remove(R.reply);
                }
                int rand = new Random().Next(0, Replies.Count);
                UsedReplies.Add(Replies[rand].reply);
                return(Replies[rand]);
            }
        }