Пример #1
0
        public static WordList CreateFromWords(IEnumerable <string> words, AffixConfig affix)
        {
            var wordListBuilder = new Builder(affix ?? new AffixConfig.Builder().MoveToImmutable());

            if (words is IList <string> wordsAsList)
            {
                wordListBuilder.InitializeEntriesByRoot(wordsAsList.Count);
            }
            else
            {
                wordListBuilder.InitializeEntriesByRoot(0);
            }

            foreach (var word in words)
            {
                var wordEntry = new WordEntry(word, FlagSet.Empty, MorphSet.Empty, WordEntryOptions.None);

                WordEntrySet entryList = !wordListBuilder.EntriesByRoot.TryGetValue(word, out entryList)
                    ? WordEntrySet.Create(wordEntry)
                    : WordEntrySet.CopyWithItemAdded(entryList, wordEntry);

                wordListBuilder.EntriesByRoot.Add(word, entryList);
            }

            return(wordListBuilder.MoveToImmutable());
        }