Beispiel #1
0
        /// <summary>
        /// Contentクラスの新しいインスタンスを初期化する
        /// </summary>
        /// <param name="text">発話テキスト</param>
#else
        /// <summary>
        /// Initializes a new instance of Content class.
        /// </summary>
        /// <param name="text">The uttered text.</param>
#endif
        public Content(string text)
        {
            var trimmed = text.Trim();
            var m       = regexSkip.Match(trimmed);

            if (m.Success)
            {
                Topic = (Topic)Enum.Parse(typeof(Topic), m.Groups[1].ToString());
            }
            else if ((m = regexAgree.Match(trimmed)).Success)
            {
                Subject = ToAgent(m.Groups[1].ToString());
                Topic   = (Topic)Enum.Parse(typeof(Topic), m.Groups[2].ToString());
                if (m.Groups[3].ToString() == "TALK")
                {
                    Utterance = new Talk(int.Parse(m.Groups[4].ToString()), int.Parse(m.Groups[5].ToString()), 0, Agent.NONE, "");
                }
                else
                {
                    Utterance = new Whisper(int.Parse(m.Groups[4].ToString()), int.Parse(m.Groups[5].ToString()), 0, Agent.NONE, "");
                }
            }
            else if ((m = regexEstimate.Match(trimmed)).Success)
            {
                Subject = ToAgent(m.Groups[1].ToString());
                Topic   = (Topic)Enum.Parse(typeof(Topic), m.Groups[2].ToString());
                Target  = ToAgent(m.Groups[3].ToString());
                Role    = (Role)Enum.Parse(typeof(Role), m.Groups[4].ToString());
            }
            else if ((m = regexDivined.Match(trimmed)).Success)
            {
                Subject = ToAgent(m.Groups[1].ToString());
                Topic   = (Topic)Enum.Parse(typeof(Topic), m.Groups[2].ToString());
                Target  = ToAgent(m.Groups[3].ToString());
                Result  = (Species)Enum.Parse(typeof(Species), m.Groups[4].ToString());
            }
            else if ((m = regexAttack.Match(trimmed)).Success)
            {
                Subject = ToAgent(m.Groups[1].ToString());
                Topic   = (Topic)Enum.Parse(typeof(Topic), m.Groups[2].ToString());
                Target  = ToAgent(m.Groups[3].ToString());
            }
            else if ((m = regexRequest.Match(trimmed)).Success)
            {
                Topic       = Topic.OPERATOR;
                Subject     = ToAgent(m.Groups[1].ToString());
                Operator    = (Operator)Enum.Parse(typeof(Operator), m.Groups[2].ToString());
                Target      = ToAgent(m.Groups[3].ToString());
                ContentList = GetContents(m.Groups[4].ToString());
            }
            else if ((m = regexBecause.Match(trimmed)).Success)
            {
                Topic       = Topic.OPERATOR;
                Subject     = ToAgent(m.Groups[1].ToString());
                Operator    = (Operator)Enum.Parse(typeof(Operator), m.Groups[2].ToString());
                ContentList = GetContents(m.Groups[3].ToString());
                if (Operator == Operator.REQUEST)
                {
                    Target = ContentList[0].Subject == Agent.NONE ? Agent.ANY : ContentList[0].Subject;
                }
            }
            else if ((m = regexDay.Match(trimmed)).Success)
            {
                Topic       = Topic.OPERATOR;
                Subject     = ToAgent(m.Groups[1].ToString());
                Operator    = Operator.DAY;
                Day         = int.Parse(m.Groups[2].ToString());
                ContentList = GetContents(m.Groups[3].ToString());
            }
            else
            {
                Topic = Topic.Skip;
            }
            CompleteInnerSubject();
            NormalizeText();
        }
Beispiel #2
0
        /// <summary>
        /// Contentクラスの新しいインスタンスを初期化する
        /// </summary>
        /// <param name="text">発話テキスト</param>
#else
        /// <summary>
        /// Initializes a new instance of Content class.
        /// </summary>
        /// <param name="text">The uttered text.</param>
#endif
        public Content(string text)
        {
            Text = text;
            string sentence = GetSentence(Text);

            if (sentence != null) // Complex sentence.
            {
                Topic       = Topic.OPERATOR;
                Operator    = Operator.REQUEST;
                ContentList = new List <Content>();
                ContentList.Add(new Content(sentence));
            }
            else // Simple sentence.
            {
                string[] split  = Text.Split();
                int      offset = 0;
                if (split[0].StartsWith("Agent"))
                {
                    Subject = Agent.GetAgent(GetInt(split[0]));
                    offset  = 1;
                }
                Topic topic;
                if (!Enum.TryParse(split[0 + offset], out topic))
                {
                    throw new AIWolfLibException("Content: Can't find any topic in " + split[0 + offset]);
                }
                Topic = topic;
                if (split.Length >= 2 + offset && split[1 + offset].StartsWith("Agent"))
                {
                    Target = Agent.GetAgent(GetInt(split[1 + offset]));
                }
                switch (Topic)
                {
                case Topic.Skip:
                case Topic.Over:
                    break;

                case Topic.AGREE:
                case Topic.DISAGREE:
                    if (split[1 + offset].Equals("TALK"))
                    {
                        Utterance = new Talk(GetInt(split[3 + offset]), GetInt(split[2 + offset]));
                    }
                    else
                    {
                        Utterance = new Whisper(GetInt(split[3 + offset]), GetInt(split[2 + offset]));
                    }
                    break;

                case Topic.ESTIMATE:
                case Topic.COMINGOUT:
                    Role role;
                    if (!Enum.TryParse(split[2 + offset], out role))
                    {
                        throw new AIWolfLibException("Content: Can't find any role in " + split[2 + offset]);
                    }
                    Role = role;
                    break;

                case Topic.DIVINED:
                case Topic.IDENTIFIED:
                    Species species;
                    if (!Enum.TryParse(split[2 + offset], out species))
                    {
                        throw new AIWolfLibException("Content: Can't find any species in " + split[2 + offset]);
                    }
                    Result = species;
                    break;

                case Topic.ATTACK:
                case Topic.DIVINATION:
                case Topic.GUARD:
                case Topic.GUARDED:
                case Topic.VOTE:
                    break;

                default:
                    break;
                }
            }
        }