Beispiel #1
0
        private async Task InitializeAsync()
        {
            AffixesPerItemType =
                (from a in await LoadAffixes()
                 group a by a.ItemType into types
                 select types)
                 .ToDictionary(g => g.Key, g => (IReadOnlyList<Affix>)new List<Affix>(g));

            BaseList = (await LoadBases()).ToList();

            var dict = new Dictionary<string, ItemBase>();
            foreach (var itemBase in BaseList)
            {
                dict[itemBase.Name] = itemBase;
            }
            BaseDictionary = dict;

            _root = new WordSetTreeNode(BaseList.Select(m => m.Name));
        }
Beispiel #2
0
            public void AddWordset(IEnumerable<string> words)
            {
                string word = words.First();
                if (_Children == null)
                    _Children = new Dictionary<string, WordSetTreeNode>();

                WordSetTreeNode nod = null;
                _Children.TryGetValue(word, out nod);

                if (nod == null)
                {
                    nod = new WordSetTreeNode() { Word = word, Parent = this, _Level = this._Level + 1 };
                    _Children.Add(word, nod);
                }

                if (words.Count() > 1)
                {
                    nod.AddWordset(words.Skip(1));
                }
                else
                    nod.IsLeaf = true;
            }
Beispiel #3
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;
        }
Beispiel #4
0
            private void AddWordset(IEnumerable<string> words)
            {
                var enumerated = words as string[] ?? words.ToArray();

                var word = enumerated.First();

                WordSetTreeNode nod;
                if (!_children.TryGetValue(word, out nod))
                {
                    nod = new WordSetTreeNode { _word = word, _parent = this, Level = Level + 1 };
                    _children.Add(word, nod);
                }

                if (enumerated.Length > 1)
                    nod.AddWordset(enumerated.Skip(1));
                else
                    nod._isLeaf = true;
            }