Beispiel #1
0
        internal List <Affix <PrefixEntry> > GetMatchingAffixes(string word)
        {
            if (string.IsNullOrEmpty(word))
            {
                return(new List <Affix <PrefixEntry> >(0));
            }

            var results = new List <Affix <PrefixEntry> >();

            if (AffixesByIndexedByKey.TryGetValue(word[0], out AffixEntryGroupCollection <PrefixEntry> indexedGroups))
            {
                foreach (var group in indexedGroups)
                {
                    foreach (var entry in group.Entries)
                    {
                        if (HunspellTextFunctions.IsSubset(entry.Key, word))
                        {
                            results.Add(Affix <PrefixEntry> .Create(entry, group));
                        }
                    }
                }
            }

            if (AffixesWithDots.HasItems)
            {
                results.AddRange(GetMatchingWithDotAffixes(word, HunspellTextFunctions.IsSubset));
            }

            return(results);
        }
        /// <summary>
        /// Forbid compoundings when there are special patterns at word bound.
        /// </summary>
        internal bool Check(string word, int pos, WordEntry r1, WordEntry r2, bool affixed)
        {
#if DEBUG
            if (word == null)
            {
                throw new ArgumentNullException(nameof(word));
            }
            if (r1 == null)
            {
                throw new ArgumentNullException(nameof(r1));
            }
            if (r2 == null)
            {
                throw new ArgumentNullException(nameof(r2));
            }
#endif

            var wordAfterPos = word.Subslice(pos);

            foreach (var patternEntry in items)
            {
                if (
                    HunspellTextFunctions.IsSubset(patternEntry.Pattern2, wordAfterPos)
                    &&
                    (
                        patternEntry.Condition.IsZero
                        ||
                        r1.ContainsFlag(patternEntry.Condition)
                    )
                    &&
                    (
                        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)
                        ||
                        PatternWordCheck(word, pos, patternEntry.Pattern.StartsWith('0') ? r1.Word : patternEntry.Pattern)
                    )
                    )
                {
                    return(true);
                }
            }

            return(false);
        }