Пример #1
0
        private bool AddWordCapitalized(string word, FlagSet flags, MorphSet morphs, CapitalizationType capType)
        {
            // add inner capitalized forms to handle the following allcap forms:
            // Mixed caps: OpenOffice.org -> OPENOFFICE.ORG
            // Allcaps with suffixes: CIA's -> CIA'S

            if (
                (
                    capType == CapitalizationType.Huh ||
                    capType == CapitalizationType.HuhInit ||
                    (capType == CapitalizationType.All && flags.HasItems)
                )
                &&
                !flags.Contains(Affix.ForbiddenWord)
                )
            {
                flags = Builder.Dedup(FlagSet.Union(flags, SpecialFlags.OnlyUpcaseFlag));

                var textInfo       = Affix.Culture.TextInfo;
                var initCapBuilder = StringBuilderPool.Get(word);
                if (initCapBuilder.Length > 0)
                {
                    initCapBuilder[0] = textInfo.ToUpper(initCapBuilder[0]);

                    for (var i = 1; i < initCapBuilder.Length; i++)
                    {
                        initCapBuilder[i] = textInfo.ToLower(initCapBuilder[i]);
                    }
                }

                return(AddWord(StringBuilderPool.GetStringAndReturn(initCapBuilder), flags, morphs, true));
            }

            return(false);
        }
            private AffixConfig ToImmutable(bool destructive)
            {
                var culture = CultureInfo.ReadOnly(Culture ?? CultureInfo.InvariantCulture);

                var config = new AffixConfig
                {
                    Options                = Options,
                    FlagMode               = FlagMode,
                    KeyString              = Dedup(KeyString ?? DefaultKeyString),
                    TryString              = Dedup(TryString ?? string.Empty),
                    Language               = Dedup(Language ?? string.Empty),
                    Culture                = culture,
                    IsHungarian            = string.Equals(culture?.TwoLetterISOLanguageName, "HU", StringComparison.OrdinalIgnoreCase),
                    StringComparer         = new CulturedStringComparer(culture),
                    CompoundFlag           = CompoundFlag,
                    CompoundBegin          = CompoundBegin,
                    CompoundEnd            = CompoundEnd,
                    CompoundMiddle         = CompoundMiddle,
                    CompoundWordMax        = CompoundWordMax,
                    CompoundMin            = CompoundMin ?? DefaultCompoundMinLength,
                    CompoundRoot           = CompoundRoot,
                    CompoundPermitFlag     = CompoundPermitFlag,
                    CompoundForbidFlag     = CompoundForbidFlag,
                    NoSuggest              = NoSuggest,
                    NoNgramSuggest         = NoNgramSuggest,
                    ForbiddenWord          = ForbiddenWord ?? SpecialFlags.ForbiddenWord,
                    LemmaPresent           = LemmaPresent,
                    Circumfix              = Circumfix,
                    OnlyInCompound         = OnlyInCompound,
                    NeedAffix              = NeedAffix,
                    MaxNgramSuggestions    = MaxNgramSuggestions ?? DefaultMaxNgramSuggestions,
                    MaxDifferency          = MaxDifferency,
                    MaxCompoundSuggestions = MaxCompoundSuggestions ?? DefaultMaxCompoundSuggestions,
                    KeepCase               = KeepCase,
                    ForceUpperCase         = ForceUpperCase,
                    Warn                = Warn,
                    SubStandard         = SubStandard,
                    CompoundSyllableNum = CompoundSyllableNum,
                    Encoding            = Encoding,
                    CompoundMaxSyllable = CompoundMaxSyllable,
                    CompoundVowels      = CompoundVowels ?? CharacterSet.Empty,
                    WordChars           = WordChars ?? CharacterSet.Empty,
                    IgnoredChars        = IgnoredChars ?? CharacterSet.Empty,
                    Version             = Dedup(Version),
                    BreakPoints         = BreakSet.Create(BreakPoints)
                };

                if (destructive)
                {
                    config.Replacements        = SingleReplacementSet.TakeList(Steal(ref Replacements));
                    config.CompoundRules       = CompoundRuleSet.TakeList(Steal(ref CompoundRules));
                    config.CompoundPatterns    = PatternSet.TakeList(Steal(ref CompoundPatterns));
                    config.RelatedCharacterMap = MapTable.TakeList(Steal(ref RelatedCharacterMap));
                    config.Phone             = PhoneTable.TakeList(Steal(ref Phone));
                    config.InputConversions  = MultiReplacementTable.TakeDictionary(Steal(ref InputConversions));
                    config.OutputConversions = MultiReplacementTable.TakeDictionary(Steal(ref OutputConversions));
                    config.Warnings          = WarningList.TakeList(Steal(ref Warnings));

                    config.aliasF = AliasF ?? new List <FlagSet>(0);
                    AliasF        = null;
                    config.aliasM = AliasM ?? new List <MorphSet>(0);
                    AliasM        = null;
                }
                else
                {
                    config.Replacements        = SingleReplacementSet.Create(Replacements);
                    config.CompoundRules       = CompoundRuleSet.Create(CompoundRules);
                    config.CompoundPatterns    = PatternSet.Create(CompoundPatterns);
                    config.RelatedCharacterMap = MapTable.Create(RelatedCharacterMap);
                    config.Phone             = PhoneTable.Create(Phone);
                    config.InputConversions  = MultiReplacementTable.Create(InputConversions);
                    config.OutputConversions = MultiReplacementTable.Create(OutputConversions);
                    config.Warnings          = WarningList.Create(Warnings);

                    config.aliasF = AliasF == null ? new List <FlagSet>(0) : AliasF.ToList();
                    config.aliasM = AliasM == null ? new List <MorphSet>(0) : AliasM.ToList();
                }

                config.Prefixes = AffixCollection <PrefixEntry> .Create(Prefixes);

                config.Suffixes = AffixCollection <SuffixEntry> .Create(Suffixes);

                config.ContClasses = FlagSet.Union(config.Prefixes.ContClasses, config.Suffixes.ContClasses);

                return(config);
            }