private bool TryParseCompoundSyllable(string parameters) { var parts = parameters.SliceOnTabOrSpace(); if (parts.Length > 0) { int maxValue; if (IntEx.TryParseInvariant(parts[0], out 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[] characters, bool restricted) : this(CharacterSet.TakeArray(characters), restricted) { }
private CharacterCondition(char character, bool restricted) : this(CharacterSet.Create(character), restricted) { }
public CharacterCondition(CharacterSet characters, bool restricted) { Characters = characters; Restricted = restricted; }
private bool TryHandleParameterizedCommand(string name, string parameters) { var commandName = name.ToUpperInvariant(); switch (commandName) { case "FLAG": // parse in the try string return(TrySetFlagMode(parameters)); case "KEY": // parse in the keyboard string Builder.KeyString = Builder.Dedup(parameters); return(true); case "TRY": // parse in the try string Builder.TryString = Builder.Dedup(parameters); return(true); case "SET": // parse in the name of the character set used by the .dict and .aff var encoding = EncodingEx.GetEncodingByName(parameters); if (encoding == null) { Builder.LogWarning("Failed to get encoding: " + parameters); return(false); } Builder.Encoding = encoding; return(true); case "LANG": // parse in the language for language specific codes Builder.Language = Builder.Dedup(parameters.Trim()); Builder.Culture = GetCultureFromLanguage(Builder.Language); return(true); case "SYLLABLENUM": // parse in the flag used by compound_check() method Builder.CompoundSyllableNum = Builder.Dedup(parameters); return(true); case "WORDCHARS": // parse in the extra word characters Builder.WordChars = CharacterSet.Create(parameters); return(true); case "IGNORE": // parse in the ignored characters (for example, Arabic optional diacretics characters) Builder.IgnoredChars = CharacterSet.Create(parameters); return(true); case "COMPOUNDFLAG": // parse in the flag used by the controlled compound words return(TryParseFlag(parameters, out Builder.CompoundFlag)); case "COMPOUNDMIDDLE": // parse in the flag used by compound words return(TryParseFlag(parameters, out Builder.CompoundMiddle)); case "COMPOUNDBEGIN": // parse in the flag used by compound words return(EnumEx.HasFlag(Builder.Options, AffixConfigOptions.ComplexPrefixes) ? TryParseFlag(parameters, out Builder.CompoundEnd) : TryParseFlag(parameters, out Builder.CompoundBegin)); case "COMPOUNDEND": // parse in the flag used by compound words return(EnumEx.HasFlag(Builder.Options, AffixConfigOptions.ComplexPrefixes) ? TryParseFlag(parameters, out Builder.CompoundBegin) : TryParseFlag(parameters, out Builder.CompoundEnd)); case "COMPOUNDWORDMAX": // parse in the data used by compound_check() method Builder.CompoundWordMax = IntEx.TryParseInvariant(parameters); return(Builder.CompoundWordMax.HasValue); case "COMPOUNDMIN": // parse in the minimal length for words in compounds 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 "COMPOUNDROOT": // parse in the flag sign compounds in dictionary return(TryParseFlag(parameters, out Builder.CompoundRoot)); case "COMPOUNDPERMITFLAG": // parse in the flag used by compound_check() method return(TryParseFlag(parameters, out Builder.CompoundPermitFlag)); case "COMPOUNDFORBIDFLAG": // parse in the flag used by compound_check() method return(TryParseFlag(parameters, out Builder.CompoundForbidFlag)); case "COMPOUNDSYLLABLE": // parse in the max. words and syllables in compounds return(TryParseCompoundSyllable(parameters)); case "NOSUGGEST": return(TryParseFlag(parameters, out Builder.NoSuggest)); case "NONGRAMSUGGEST": return(TryParseFlag(parameters, out Builder.NoNgramSuggest)); case "FORBIDDENWORD": // parse in the flag used by forbidden words Builder.ForbiddenWord = TryParseFlag(parameters); return(Builder.ForbiddenWord.HasValue); case "LEMMA_PRESENT": // parse in the flag used by forbidden words return(TryParseFlag(parameters, out Builder.LemmaPresent)); case "CIRCUMFIX": // parse in the flag used by circumfixes return(TryParseFlag(parameters, out Builder.Circumfix)); case "ONLYINCOMPOUND": // parse in the flag used by fogemorphemes return(TryParseFlag(parameters, out Builder.OnlyInCompound)); case "PSEUDOROOT": // parse in the flag used by `needaffixs' case "NEEDAFFIX": // parse in the flag used by `needaffixs' return(TryParseFlag(parameters, out Builder.NeedAffix)); case "REP": // parse in the typical fault correcting table return(TryParseStandardListItem(EntryListType.Replacements, parameters, ref Builder.Replacements, TryParseReplacements)); case "ICONV": // parse in the input conversion table return(TryParseConv(parameters, EntryListType.Iconv, ref Builder.InputConversions)); case "OCONV": // parse in the output conversion table return(TryParseConv(parameters, EntryListType.Oconv, ref Builder.OutputConversions)); case "PHONE": // parse in the phonetic conversion table return(TryParseStandardListItem(EntryListType.Phone, parameters, ref Builder.Phone, TryParsePhone)); case "CHECKCOMPOUNDPATTERN": // parse in the checkcompoundpattern table return(TryParseStandardListItem(EntryListType.CompoundPatterns, parameters, ref Builder.CompoundPatterns, TryParseCheckCompoundPatternIntoCompoundPatterns)); case "COMPOUNDRULE": // parse in the defcompound table return(TryParseStandardListItem(EntryListType.CompoundRules, parameters, ref Builder.CompoundRules, TryParseCompoundRuleIntoList)); case "MAP": // parse in the related character map table return(TryParseStandardListItem(EntryListType.Map, parameters, ref Builder.RelatedCharacterMap, TryParseMapEntry)); case "BREAK": // parse in the word breakpoints table return(TryParseStandardListItem(EntryListType.Break, parameters, ref Builder.BreakPoints, TryParseBreak)); case "VERSION": Builder.Version = parameters; return(true); case "MAXNGRAMSUGS": Builder.MaxNgramSuggestions = IntEx.TryParseInvariant(parameters); return(Builder.MaxNgramSuggestions.HasValue); case "MAXDIFF": Builder.MaxDifferency = IntEx.TryParseInvariant(parameters); return(Builder.MaxDifferency.HasValue); case "MAXCPDSUGS": Builder.MaxCompoundSuggestions = IntEx.TryParseInvariant(parameters); return(Builder.MaxCompoundSuggestions.HasValue); case "KEEPCASE": // parse in the flag used by forbidden words return(TryParseFlag(parameters, out Builder.KeepCase)); case "FORCEUCASE": return(TryParseFlag(parameters, out Builder.ForceUpperCase)); case "WARN": return(TryParseFlag(parameters, out Builder.Warn)); case "SUBSTANDARD": return(TryParseFlag(parameters, out Builder.SubStandard)); case "PFX": case "SFX": var parseAsPrefix = "PFX" == commandName; if (EnumEx.HasFlag(Builder.Options, AffixConfigOptions.ComplexPrefixes)) { parseAsPrefix = !parseAsPrefix; } return(parseAsPrefix ? TryParseAffixIntoList(parameters, ref Builder.Prefixes) : TryParseAffixIntoList(parameters, ref Builder.Suffixes)); case "AF": return(TryParseStandardListItem(EntryListType.AliasF, parameters, ref Builder.AliasF, TryParseAliasF)); case "AM": return(TryParseStandardListItem(EntryListType.AliasM, parameters, ref Builder.AliasM, TryParseAliasM)); default: Builder.LogWarning($"Unknown command {commandName} with params: {parameters}"); return(false); } }