Пример #1
0
        private static TagInf ParseRelation(string self, string[] lns)
        {
            TagInf t = new TagInf();

            t.Alias.Add(self);
            foreach (string ln in lns)
            {
                string tmp = ln.Trim();
                if (tmp.Length == 0)
                {
                    continue;
                }
                char     type     = tmp[0];
                string   tags     = tmp.Substring(1);
                string[] tagArray = tags.Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries);
                switch (type)
                {
                case '=': t.Alias.AddRange(tagArray.ToList <string>()); break;

                case '<': t.Parents.AddRange(tagArray.ToList <string>()); break;

                case '>': t.Children.AddRange(tagArray.ToList <string>()); break;

                case '~': t.Brothers.AddRange(tagArray.ToList <string>()); break;
                }
            }
            if (t.Alias.Count == 0)
            {
                return(null);
            }

            return(t);
        }
Пример #2
0
        public string AddTag(string sentence)
        {
            TagInf tagInf = TagInf.ParseTRG(sentence);
            string tag    = null;

            if (tagInf != null)
            {
                if (tagInf.GetAlias().Count > 0)
                {
                    tag = tagInf.GetAlias()[0];
                    if (tagInf.GetChdren().Count == 0)
                    {
                        AddTag(tag, null);
                    }
                    foreach (string c in tagInf.GetChdren())
                    {
                        AddTag(tag, c);
                    }
                    foreach (string a in tagInf.GetAlias())
                    {
                        AddTag(tag, a);
                    }
                    //Update(tag);
                }
            }
            return(tag);
        }