/// <summary> /// Forbid compoundings when there are special patterns at word bound. /// </summary> public bool Check(string word, int pos, WordEntry r1, WordEntry r2, bool affixed) { var wordAfterPos = word.Substring(pos); foreach (var patternEntry in items) { int len; if ( StringEx.IsSubset(patternEntry.Pattern2, wordAfterPos) && ( r1 == null || patternEntry.Condition.IsZero || r1.ContainsFlag(patternEntry.Condition) ) && ( r2 == null || patternEntry.Condition2.IsZero || r2.ContainsFlag(patternEntry.Condition2) ) && // zero length pattern => only TESTAFF // zero pattern (0/flag) => unmodified stem (zero affixes allowed) ( string.IsNullOrEmpty(patternEntry.Pattern) || ( ( patternEntry.Pattern.StartsWith('0') && r1.Word.Length <= pos && StringEx.EqualsOffset(word, pos - r1.Word.Length, r1.Word, 0, r1.Word.Length) ) || ( !patternEntry.Pattern.StartsWith('0') && ( ( len = patternEntry.Pattern.Length ) != 0 ) && StringEx.EqualsOffset(word, pos - len, patternEntry.Pattern, 0, len) ) ) ) ) { return(true); } } return(false); }
public bool EntryContainsRuleFlags(WordEntry rv) { foreach (var rule in items) { foreach (var flag in rule) { if (!flag.Equals('*') && !flag.Equals('?') && rv.ContainsFlag(flag)) { return(true); } } } return(false); }
private bool AddWord(string word, FlagSet flags, MorphSet morphs, bool onlyUpperCase) { if (Affix.IgnoredChars.HasItems) { word = word.RemoveChars(Affix.IgnoredChars); } if (Affix.ComplexPrefixes) { word = word.Reverse(); if (morphs.HasItems && !Affix.IsAliasM) { var newMorphs = new string[morphs.Count]; for (int i = 0; i < morphs.Count; i++) { newMorphs[i] = morphs[morphs.Count - i - 1].Reverse(); } morphs = MorphSet.TakeArray(newMorphs); } } WordEntryOptions options; if (morphs.HasItems) { if (Affix.IsAliasM) { options = WordEntryOptions.AliasM; var morphBuilder = new List <string>(); foreach (var originalValue in morphs) { int morphNumber; MorphSet aliasedMorph; if (IntEx.TryParseInvariant(originalValue, out morphNumber) && Affix.TryGetAliasM(morphNumber, out aliasedMorph)) { morphBuilder.AddRange(aliasedMorph); } else { morphBuilder.Add(originalValue); } } morphs = MorphSet.Create(morphBuilder); } else { options = WordEntryOptions.None; } if (morphs.AnyStartsWith(MorphologicalTags.Phon)) { options |= WordEntryOptions.Phon; } } else { options = WordEntryOptions.None; } bool saveEntryList = false; WordEntrySet entryList; word = Builder.Dedup(word); if (!Builder.EntriesByRoot.TryGetValue(word, out entryList)) { saveEntryList = true; entryList = WordEntrySet.Empty; } var upperCaseHomonym = false; for (var i = 0; i < entryList.Count; i++) { var existingEntry = entryList[i]; if (!onlyUpperCase) { if (existingEntry.ContainsFlag(SpecialFlags.OnlyUpcaseFlag)) { existingEntry = new WordEntry( existingEntry.Word, flags, existingEntry.Morphs, existingEntry.Options); entryList.DestructiveReplace(i, existingEntry); return(false); } } else { upperCaseHomonym = true; } } if (!upperCaseHomonym) { saveEntryList = true; entryList = WordEntrySet.CopyWithItemAdded(entryList, new WordEntry( word, flags, Builder.Dedup(morphs), options)); } if (saveEntryList) { Builder.EntriesByRoot[word] = entryList; } return(false); }
private bool IsKeepCase(WordEntry rv) => rv.ContainsFlag(Affix.KeepCase);