コード例 #1
0
            public TemplateWord(string fullTemplate, int startIndex, int length)
            {
                content     = fullTemplate.Substring(startIndex, length);
                start       = startIndex;
                this.length = length;
                group       = 0;

                PoS = null;
                string contentCopy = content;

                if (contentCopy[0] == '@')
                {
                    int tempGroup;
                    int endGroupIndex = contentCopy.LastIndexOfAny("0123456789".ToCharArray(), 3);
                    if (endGroupIndex > 0)
                    {
                        if (int.TryParse(contentCopy.Substring(1, endGroupIndex), out tempGroup))
                        {
                            group = tempGroup;
                        }
                    }
                    else
                    {
                        endGroupIndex = 0;
                    }
                    contentCopy = contentCopy.Substring(endGroupIndex + 1);
                }
                if (contentCopy[0] == '[' && contentCopy[contentCopy.Length - 1] == ']')
                {
                    PoS = PartOfSpeech.FromTag(contentCopy.Substring(1, contentCopy.Length - 2));
                    if (PoS != null)
                    {
                        IsHook = true;
                    }
                }
                else if (contentCopy[0] == '<' && contentCopy[contentCopy.Length - 1] == '>')
                {
                    int indexOfPoSStart = contentCopy.IndexOf('[');
                    if (indexOfPoSStart != -1 && contentCopy[contentCopy.Length - 2] == ']')
                    {
                        string posTag = contentCopy.Substring(indexOfPoSStart + 1, contentCopy.Length - indexOfPoSStart - 3);
                        PoS = PartOfSpeech.FromTag(posTag);
                        if (PoS != null)
                        {
                            Word   = new Word(contentCopy.Substring(1, indexOfPoSStart - 1), PoS, 1);
                            IsHook = false;
                        }
                    }
                    if (PoS == null)
                    {
                        Word   = WordDictionary.Instance.GetWordByValue(contentCopy.Substring(1, contentCopy.Length - 2));
                        IsHook = false;
                    }
                }
                else
                {
                    Word tempWord = WordDictionary.Instance.GetWordByValue(contentCopy);
                    if (tempWord.PoS != PartOfSpeech.Unclassified)
                    {
                        PoS    = tempWord.PoS;
                        IsHook = true;
                    }
                }

                if (PoS == null && Word == null)
                {
                    Word   = WordDictionary.Instance.GetWordByValue(contentCopy);
                    IsHook = false;
                }
            }