CheckCondition() public method

Checks whether the String defined by the provided char array, offset and length, meets the condition of this affix.
public CheckCondition ( String text ) : System.Boolean
text String
return System.Boolean
Esempio n. 1
0
        /// <summary>
        ///   Applies the affix rule to the given word, producing a list of stems if any are found.
        /// </summary>
        /// <param name="strippedWord">Word the affix has been removed and the strip added.</param>
        /// <param name="affix">HunspellAffix representing the affix rule itself.</param>
        /// <param name="recursionDepth">Level of recursion this stemming step is at.</param>
        /// <returns>List of stems for the word, or an empty list if none are found.</returns>
        public IEnumerable<HunspellStem> ApplyAffix(String strippedWord, HunspellAffix affix, Int32 recursionDepth)
        {
            if (strippedWord == null) throw new ArgumentNullException("strippedWord");
            if (affix == null) throw new ArgumentNullException("affix");

            if (!affix.CheckCondition(strippedWord)) {
                return new List<HunspellStem>();
            }

            var words = _dictionary.LookupWord(strippedWord);
            if (words == null) {
                return new List<HunspellStem>();
            }

            var stems = new List<HunspellStem>();

            foreach (var hunspellWord in words) {
                if (hunspellWord.HasFlag(affix.Flag)) {
                    if (affix.IsCrossProduct && recursionDepth < RECURSION_CAP) {
                        var recursiveStems = Stem(strippedWord, affix.AppendFlags, ++recursionDepth);
                        if (recursiveStems.Any()) {
                            stems.AddRange(recursiveStems);
                        } else {
                            stems.Add(new HunspellStem(strippedWord));
                        }
                    } else {
                        stems.Add(new HunspellStem(strippedWord));
                    }
                }
            }

            return stems;
        }
        /// <summary>
        ///   Applies the affix rule to the given word, producing a list of stems if any are found.
        /// </summary>
        /// <param name="strippedWord">Word the affix has been removed and the strip added.</param>
        /// <param name="affix">HunspellAffix representing the affix rule itself.</param>
        /// <param name="recursionDepth">Level of recursion this stemming step is at.</param>
        /// <returns>List of stems for the word, or an empty list if none are found.</returns>
        public IEnumerable <HunspellStem> ApplyAffix(String strippedWord, HunspellAffix affix, Int32 recursionDepth)
        {
            if (strippedWord == null)
            {
                throw new ArgumentNullException("strippedWord");
            }
            if (affix == null)
            {
                throw new ArgumentNullException("affix");
            }

            if (!affix.CheckCondition(strippedWord))
            {
                return(new List <HunspellStem>());
            }

            var words = _dictionary.LookupWord(strippedWord);

            if (words == null)
            {
                return(new List <HunspellStem>());
            }

            var stems = new List <HunspellStem>();

            foreach (var hunspellWord in words)
            {
                if (hunspellWord.HasFlag(affix.Flag))
                {
                    if (affix.IsCrossProduct && recursionDepth < RECURSION_CAP)
                    {
                        var recursiveStems = Stem(strippedWord, affix.AppendFlags, ++recursionDepth);
                        if (recursiveStems.Any())
                        {
                            stems.AddRange(recursiveStems);
                        }
                        else
                        {
                            stems.Add(new HunspellStem(strippedWord));
                        }
                    }
                    else
                    {
                        stems.Add(new HunspellStem(strippedWord));
                    }
                }
            }

            return(stems);
        }