예제 #1
0
 private AffixCollection
 (
     Dictionary <FlagValue, AffixEntryGroup <TEntry> > affixesByFlag,
     Dictionary <char, AffixEntryWithDetailCollection <TEntry> > affixesByIndexedByKey,
     AffixEntryWithDetailCollection <TEntry> affixesWithDots,
     AffixEntryWithDetailCollection <TEntry> affixesWithEmptyKeys,
     FlagSet contClasses
 )
 {
     this.affixesByFlag         = affixesByFlag;
     this.affixesByIndexedByKey = affixesByIndexedByKey;
     this.affixesWithDots       = affixesWithDots;
     AffixesWithEmptyKeys       = affixesWithEmptyKeys;
     ContClasses = contClasses;
     HasAffixes  = affixesByFlag.Count != 0;
     IsEmpty     = !HasAffixes;
 }
예제 #2
0
        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)
                   ));
        }