Ejemplo n.º 1
0
        /// <summary>
        ///     Expands an affix compressed base word
        /// </summary>
        /// <param name="word" type="GuruComponents.Netrix.SpellChecker.NetSpell.Dictionary.Word">
        ///     <para>
        ///         The word to expand
        ///     </para>
        /// </param>
        /// <returns>
        ///     A System.Collections.ArrayList of words expanded from base word
        /// </returns>
        public ArrayList ExpandWord(Word word)
        {
            ArrayList suffixWords = new ArrayList();
            ArrayList words       = new ArrayList();

            suffixWords.Add(word.Text);
            string prefixKeys = "";


            // check suffix keys first
            foreach (char key in word.AffixKeys)
            {
                if (_suffixRules.ContainsKey(key.ToString(CultureInfo.CurrentUICulture)))
                {
                    AffixRule rule     = _suffixRules[key.ToString(CultureInfo.CurrentUICulture)];
                    string    tempWord = AffixUtility.AddSuffix(word.Text, rule);
                    if (tempWord != word.Text)
                    {
                        if (rule.AllowCombine)
                        {
                            suffixWords.Add(tempWord);
                        }
                        else
                        {
                            words.Add(tempWord);
                        }
                    }
                }
                else if (_prefixRules.ContainsKey(key.ToString(CultureInfo.CurrentUICulture)))
                {
                    prefixKeys += key.ToString(CultureInfo.CurrentUICulture);
                }
            }

            // apply prefixes
            foreach (char key in prefixKeys)
            {
                AffixRule rule = _prefixRules[key.ToString(CultureInfo.CurrentUICulture)];
                // apply prefix to all suffix words
                foreach (string suffixWord in suffixWords)
                {
                    string tempWord = AffixUtility.AddPrefix(suffixWord, rule);
                    if (tempWord != suffixWord)
                    {
                        words.Add(tempWord);
                    }
                }
            }

            words.AddRange(suffixWords);

            //System.Diagnostics.Debug.WriteLine("Word Expanded: {0}; Child Words: {1}", word.Text, words.Count);
            return(words);
        }
        /// <summary>
        ///     Expands an affix compressed base word
        /// </summary>
        /// <param name="word" type="NetSpell.SpellChecker.Dictionary.Word">
        ///     <para>
        ///         The word to expand
        ///     </para>
        /// </param>
        /// <returns>
        ///     A System.Collections.Generic.List<string> of words expanded from base word
        /// </returns>
        public List <string> ExpandWord(Word word)
        {
            List <string> suffixWords = new List <string>();
            List <string> words       = new List <string>();

            suffixWords.Add(word.Text);
            string prefixKeys = "";


            // check suffix keys first
            foreach (char key in word.AffixKeys)
            {
                if (_suffixRules.ContainsKey(key.ToString(CultureInfo.CurrentUICulture)))
                {
                    AffixRule rule     = _suffixRules[key.ToString(CultureInfo.CurrentUICulture)];
                    string    tempWord = AffixUtility.AddSuffix(word.Text, rule);
                    if (tempWord != word.Text)
                    {
                        if (rule.AllowCombine)
                        {
                            suffixWords.Add(tempWord);
                        }
                        else
                        {
                            words.Add(tempWord);
                        }
                    }
                }
                else if (_prefixRules.ContainsKey(key.ToString(CultureInfo.CurrentUICulture)))
                {
                    prefixKeys += key.ToString(CultureInfo.CurrentUICulture);
                }
            }

            // apply prefixes
            foreach (char key in prefixKeys)
            {
                AffixRule rule = _prefixRules[key.ToString(CultureInfo.CurrentUICulture)];
                // apply prefix to all suffix words
                foreach (string suffixWord in suffixWords)
                {
                    string tempWord = AffixUtility.AddPrefix(suffixWord, rule);
                    if (tempWord != suffixWord)
                    {
                        words.Add(tempWord);
                    }
                }
            }

            words.AddRange(suffixWords);

            TraceWriter.TraceVerbose("Word Expanded: {0}; Child Words: {1}", word.Text, words.Count);
            return(words);
        }