Example #1
0
        public static string ItemTypeFromTypeline(string typeline)
        {
            if (BaseList != null)
            {
                if (_root == null)
                {
                    _root = new WordSetTreeNode();
                    var allbs = BaseList.Select(m => m.ItemType.Split(' ')).OrderBy(s => s[0]).ToArray();
                    foreach (var wl in allbs)
                    {
                        _root.AddWordset(wl);
                    }
                }

                var wlist = typeline.Split(' ');

                List <WordSetTreeNode> ms = new List <WordSetTreeNode>();

                for (int i = 0; i < wlist.Length; i++)
                {
                    var m = _root.Match(wlist.Skip(i)).OrderByDescending(n => n.Level).FirstOrDefault();
                    if (m != null)
                    {
                        ms.Add(m);
                    }
                }

                if (ms.Count == 0)
                {
                    return(typeline);
                }
                else if (ms.Count > 1)
                {
                    throw new NotImplementedException("duplicate type match");
                }
                else
                {
                    return(ms[0].ToString());
                }
            }

            return(typeline);
        }