public static async Task <WordList> ReadFileAsync(string dictionaryFilePath, AffixConfig affix, WordList.Builder builder = null) { using (var stream = File.Open(dictionaryFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { return(await ReadAsync(stream, affix, builder).ConfigureAwait(false)); } }
public static WordList Read(Stream dictionaryStream, AffixConfig affix, WordList.Builder builder = null) { using (var reader = new StaticEncodingLineReader(dictionaryStream, affix.Encoding)) { return(Read(reader, affix, builder)); } }
public static async Task <WordList> ReadAsync(Stream dictionaryStream, AffixConfig affix, WordList.Builder builder = null) { using (var reader = new StaticEncodingLineReader(dictionaryStream, affix.Encoding)) { return(await ReadAsync(reader, affix, builder).ConfigureAwait(false)); } }
public static WordList ReadFile(string dictionaryFilePath, AffixConfig affix, WordList.Builder builder = null) { using (var stream = File.Open(dictionaryFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { return(Read(stream, affix, builder)); } }
internal Builder(AffixConfig affix, Deduper <FlagSet> flagSetDeduper, Deduper <MorphSet> morphSet, StringDeduper stringDeduper) { Affix = affix; FlagSetDeduper = flagSetDeduper ?? new Deduper <FlagSet>(FlagSet.DefaultComparer); FlagSetDeduper.Add(FlagSet.Empty); StringDeduper = stringDeduper ?? new StringDeduper(); StringDeduper.Add(MorphologicalTags.Phon); MorphSetDeduper = morphSet ?? new Deduper <MorphSet>(MorphSet.DefaultComparer); MorphSetDeduper.Add(MorphSet.Empty); }
public static WordList Read(IHunspellLineReader dictionaryReader, AffixConfig affix, WordList.Builder builder = null) { var readerInstance = new WordListReader(builder, affix); string line; while ((line = dictionaryReader.ReadLine()) != null) { readerInstance.ParseLine(line); } return(readerInstance.Builder.MoveToImmutable()); }
public Builder(AffixConfig affix) : this(affix, null, null, null) { }
private WordList(AffixConfig affix) { Affix = affix; }
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); }
public static async Task <WordList> ReadAsync(IHunspellLineReader dictionaryReader, AffixConfig affix, WordList.Builder builder = null) { var readerInstance = new WordListReader(builder, affix); string line; while ((line = await dictionaryReader.ReadLineAsync().ConfigureAwait(false)) != null) { readerInstance.ParseLine(line); } return(readerInstance.Builder.MoveToImmutable()); }
private WordListReader(WordList.Builder builder, AffixConfig affix) { Builder = builder ?? new WordList.Builder(affix); Affix = affix; }
internal static CapitalizationType GetCapitalizationType(StringSlice word, AffixConfig affix) { if (word.IsNullOrEmpty) { return(CapitalizationType.None); } var hasFoundMoreCaps = false; var firstIsUpper = false; var hasLower = false; var c = word.Text[word.Offset]; if (char.IsUpper(c)) { firstIsUpper = true; } else if (!CharIsNeutral(c, affix)) { hasLower = true; } var wordIndexLimit = word.Length + word.Offset; for (int i = word.Offset + 1; i < wordIndexLimit; i++) { c = word.Text[i]; if (char.IsUpper(c)) { hasFoundMoreCaps = true; } else if (!CharIsNeutral(c, affix)) { hasLower = true; } if (hasLower && hasFoundMoreCaps) { break; } } if (firstIsUpper) { if (!hasFoundMoreCaps) { return(CapitalizationType.Init); } if (!hasLower) { return(CapitalizationType.All); } return(CapitalizationType.HuhInit); } else { if (!hasFoundMoreCaps) { return(CapitalizationType.None); } if (!hasLower) { return(CapitalizationType.All); } return(CapitalizationType.Huh); } }
public static CapitalizationType GetCapitalizationType(string word, AffixConfig affix) { return(GetCapitalizationType(StringSlice.Create(word), affix)); }
private static bool CharIsNeutral(char c, AffixConfig affix) => !char.IsLower(c) || (c > 127 && affix.Culture.TextInfo.ToUpper(c) == c);