private bool TryParseCompoundSyllable(string parameters) { var parts = parameters.SliceOnTabOrSpace(); if (parts.Length > 0) { if (IntEx.TryParseInvariant(parts[0], out int maxValue)) { Builder.CompoundMaxSyllable = maxValue; } else { Builder.LogWarning("Failed to parse CompoundMaxSyllable value from: " + parameters); return(false); } } Builder.CompoundVowels = 1 < parts.Length ? CharacterSet.Create(parts[1]) : DefaultCompoundVowels; return(true); }
private CharacterCondition(char character, bool restricted) : this(CharacterSet.Create(character), restricted) { }
private bool TryHandleParameterizedCommand(string commandName, string parameters) { if (commandName == null || !CommandMap.TryGetValue(commandName, out AffixReaderCommandKind command)) { Builder.LogWarning($"Unknown command {commandName} with params: {parameters}"); return(false); } switch (command) { case AffixReaderCommandKind.Flag: return(TrySetFlagMode(parameters)); case AffixReaderCommandKind.KeyString: Builder.KeyString = Builder.Dedup(parameters); return(true); case AffixReaderCommandKind.TryString: Builder.TryString = Builder.Dedup(parameters); return(true); case AffixReaderCommandKind.SetEncoding: var encoding = EncodingEx.GetEncodingByName(parameters); if (encoding == null) { Builder.LogWarning("Failed to get encoding: " + parameters); return(false); } Builder.Encoding = encoding; return(true); case AffixReaderCommandKind.Language: Builder.Language = Builder.Dedup(parameters.Trim()); Builder.Culture = GetCultureFromLanguage(Builder.Language); return(true); case AffixReaderCommandKind.CompoundSyllableNum: Builder.CompoundSyllableNum = Builder.Dedup(parameters); return(true); case AffixReaderCommandKind.WordChars: Builder.WordChars = CharacterSet.Create(parameters); return(true); case AffixReaderCommandKind.Ignore: Builder.IgnoredChars = CharacterSet.Create(parameters); return(true); case AffixReaderCommandKind.CompoundFlag: return(TryParseFlag(parameters, out Builder.CompoundFlag)); case AffixReaderCommandKind.CompoundMiddle: return(TryParseFlag(parameters, out Builder.CompoundMiddle)); case AffixReaderCommandKind.CompoundBegin: return(EnumEx.HasFlag(Builder.Options, AffixConfigOptions.ComplexPrefixes) ? TryParseFlag(parameters, out Builder.CompoundEnd) : TryParseFlag(parameters, out Builder.CompoundBegin)); case AffixReaderCommandKind.CompoundEnd: return(EnumEx.HasFlag(Builder.Options, AffixConfigOptions.ComplexPrefixes) ? TryParseFlag(parameters, out Builder.CompoundBegin) : TryParseFlag(parameters, out Builder.CompoundEnd)); case AffixReaderCommandKind.CompoundWordMax: Builder.CompoundWordMax = IntEx.TryParseInvariant(parameters); return(Builder.CompoundWordMax.HasValue); case AffixReaderCommandKind.CompoundMin: Builder.CompoundMin = IntEx.TryParseInvariant(parameters); if (!Builder.CompoundMin.HasValue) { Builder.LogWarning("Failed to parse CompoundMin: " + parameters); return(false); } if (Builder.CompoundMin.GetValueOrDefault() < 1) { Builder.CompoundMin = 1; } return(true); case AffixReaderCommandKind.CompoundRoot: return(TryParseFlag(parameters, out Builder.CompoundRoot)); case AffixReaderCommandKind.CompoundPermitFlag: return(TryParseFlag(parameters, out Builder.CompoundPermitFlag)); case AffixReaderCommandKind.CompoundForbidFlag: return(TryParseFlag(parameters, out Builder.CompoundForbidFlag)); case AffixReaderCommandKind.CompoundSyllable: return(TryParseCompoundSyllable(parameters)); case AffixReaderCommandKind.NoSuggest: return(TryParseFlag(parameters, out Builder.NoSuggest)); case AffixReaderCommandKind.NoNGramSuggest: return(TryParseFlag(parameters, out Builder.NoNgramSuggest)); case AffixReaderCommandKind.ForbiddenWord: Builder.ForbiddenWord = TryParseFlag(parameters); return(Builder.ForbiddenWord.HasValue); case AffixReaderCommandKind.LemmaPresent: return(TryParseFlag(parameters, out Builder.LemmaPresent)); case AffixReaderCommandKind.Circumfix: return(TryParseFlag(parameters, out Builder.Circumfix)); case AffixReaderCommandKind.OnlyInCompound: return(TryParseFlag(parameters, out Builder.OnlyInCompound)); case AffixReaderCommandKind.NeedAffix: return(TryParseFlag(parameters, out Builder.NeedAffix)); case AffixReaderCommandKind.Replacement: return(TryParseStandardListItem(EntryListType.Replacements, parameters, ref Builder.Replacements, TryParseReplacements)); case AffixReaderCommandKind.InputConversions: return(TryParseConv(parameters, EntryListType.Iconv, ref Builder.InputConversions)); case AffixReaderCommandKind.OutputConversions: return(TryParseConv(parameters, EntryListType.Oconv, ref Builder.OutputConversions)); case AffixReaderCommandKind.Phone: return(TryParseStandardListItem(EntryListType.Phone, parameters, ref Builder.Phone, TryParsePhone)); case AffixReaderCommandKind.CheckCompoundPattern: return(TryParseStandardListItem(EntryListType.CompoundPatterns, parameters, ref Builder.CompoundPatterns, TryParseCheckCompoundPatternIntoCompoundPatterns)); case AffixReaderCommandKind.CompoundRule: return(TryParseStandardListItem(EntryListType.CompoundRules, parameters, ref Builder.CompoundRules, TryParseCompoundRuleIntoList)); case AffixReaderCommandKind.Map: return(TryParseStandardListItem(EntryListType.Map, parameters, ref Builder.RelatedCharacterMap, TryParseMapEntry)); case AffixReaderCommandKind.Break: return(TryParseStandardListItem(EntryListType.Break, parameters, ref Builder.BreakPoints, TryParseBreak)); case AffixReaderCommandKind.Version: Builder.Version = parameters; return(true); case AffixReaderCommandKind.MaxNgramSuggestions: Builder.MaxNgramSuggestions = IntEx.TryParseInvariant(parameters); return(Builder.MaxNgramSuggestions.HasValue); case AffixReaderCommandKind.MaxDifferency: Builder.MaxDifferency = IntEx.TryParseInvariant(parameters); return(Builder.MaxDifferency.HasValue); case AffixReaderCommandKind.MaxCompoundSuggestions: Builder.MaxCompoundSuggestions = IntEx.TryParseInvariant(parameters); return(Builder.MaxCompoundSuggestions.HasValue); case AffixReaderCommandKind.KeepCase: return(TryParseFlag(parameters, out Builder.KeepCase)); case AffixReaderCommandKind.ForceUpperCase: return(TryParseFlag(parameters, out Builder.ForceUpperCase)); case AffixReaderCommandKind.Warn: return(TryParseFlag(parameters, out Builder.Warn)); case AffixReaderCommandKind.SubStandard: return(TryParseFlag(parameters, out Builder.SubStandard)); case AffixReaderCommandKind.Prefix: case AffixReaderCommandKind.Suffix: var parseAsPrefix = AffixReaderCommandKind.Prefix == command; if (EnumEx.HasFlag(Builder.Options, AffixConfigOptions.ComplexPrefixes)) { parseAsPrefix = !parseAsPrefix; } return(parseAsPrefix ? TryParseAffixIntoList(parameters, ref Builder.Prefixes) : TryParseAffixIntoList(parameters, ref Builder.Suffixes)); case AffixReaderCommandKind.AliasF: return(TryParseStandardListItem(EntryListType.AliasF, parameters, ref Builder.AliasF, TryParseAliasF)); case AffixReaderCommandKind.AliasM: return(TryParseStandardListItem(EntryListType.AliasM, parameters, ref Builder.AliasM, TryParseAliasM)); default: Builder.LogWarning($"Unknown parsed command {command}"); return(false); } }