private WordList ToImmutable(bool destructive) { var affix = Affix ?? new AffixConfig.Builder().MoveToImmutable(); var nGramRestrictedFlags = Dedup(FlagSet.Create( new[] { affix.ForbiddenWord, affix.NoSuggest, affix.NoNgramSuggest, affix.OnlyInCompound, SpecialFlags.OnlyUpcaseFlag } .Where(f => f.HasValue))); var result = new WordList(affix) { NGramRestrictedFlags = nGramRestrictedFlags, }; if (destructive) { result.EntriesByRoot = EntriesByRoot ?? new Dictionary <string, WordEntrySet>(); EntriesByRoot = null; } else { result.EntriesByRoot = EntriesByRoot == null ? new Dictionary <string, WordEntrySet>() : new Dictionary <string, WordEntrySet>(EntriesByRoot); } var nGramRestrictedEntries = new HashSet <WordEntry>(); foreach (var rootSet in result.EntriesByRoot) { foreach (var entry in rootSet.Value) { if (nGramRestrictedFlags.ContainsAny(entry.Flags)) { nGramRestrictedEntries.Add(entry); } } } result.NGramRestrictedEntries = nGramRestrictedEntries; return(result); }
public static AffixCollection <TEntry> Create(List <AffixEntryGroup.Builder <TEntry> > builders) { if (builders == null || builders.Count == 0) { return(Empty); } var affixesByFlag = new Dictionary <FlagValue, AffixEntryGroup <TEntry> >(builders.Count); var affixesByIndexedByKeyBuilders = new Dictionary <char, List <AffixEntryWithDetail <TEntry> > >(); var affixesWithDots = new List <AffixEntryWithDetail <TEntry> >(); var affixesWithEmptyKeys = new List <AffixEntryWithDetail <TEntry> >(); var contClasses = new HashSet <FlagValue>(); foreach (var builder in builders) { var group = builder.ToGroup(); affixesByFlag.Add(group.AFlag, group); foreach (var entry in group.Entries) { var key = entry.Key; contClasses.UnionWith(entry.ContClass); var entryWithDetail = new AffixEntryWithDetail <TEntry>(group, entry); if (string.IsNullOrEmpty(key)) { affixesWithEmptyKeys.Add(entryWithDetail); } else { if (key.Contains('.')) { affixesWithDots.Add(entryWithDetail); } else { var indexedKey = key[0]; List <AffixEntryWithDetail <TEntry> > keyedAffixes; if (!affixesByIndexedByKeyBuilders.TryGetValue(indexedKey, out keyedAffixes)) { keyedAffixes = new List <AffixEntryWithDetail <TEntry> >(); affixesByIndexedByKeyBuilders.Add(indexedKey, keyedAffixes); } keyedAffixes.Add(entryWithDetail); } } } } var affixesByIndexedByKey = new Dictionary <char, AffixEntryWithDetailCollection <TEntry> >( affixesByIndexedByKeyBuilders.Count); foreach (var keyedBuilder in affixesByIndexedByKeyBuilders) { affixesByIndexedByKey.Add(keyedBuilder.Key, AffixEntryWithDetailCollection <TEntry> .TakeList(keyedBuilder.Value)); } return(new AffixCollection <TEntry> ( affixesByFlag, affixesByIndexedByKey, AffixEntryWithDetailCollection <TEntry> .TakeList(affixesWithDots), AffixEntryWithDetailCollection <TEntry> .TakeList(affixesWithEmptyKeys), FlagSet.Create(contClasses) )); }
internal static FlagSet ParseNumberFlags(StringSlice text) => FlagSet.Create(ParseNumberFlagsInOrder(text));
public static FlagSet ParseNumberFlags(string text, int startIndex, int length) => FlagSet.Create(ParseNumberFlagsInOrder(text, startIndex, length));