/// <summary>
        ///     Search for the longest among the following suffixes, and perform the action indicated.
        ///     eed   eedly+
        ///     replace by ee if in R1
        ///     ed   edly+   ing   ingly+
        ///     delete if the preceding word part contains a vowel, and then
        ///     if the word ends at, bl or iz add e (so luxuriat -> luxuriate), or
        ///     if the word ends with a double remove the last letter (so hopp -> hop), or
        ///     if the word is short, add e (so hop -> hope)
        /// </summary>
        internal void StripSuffixStep1b()
        {
            // eed   eedly+ - replace by ee if in R1
            if (Stem.EndsWith("eed") ||
                Stem.EndsWith("eedly"))
            {
                if (EndsWithAndInR1("eed") ||
                    EndsWithAndInR1("eedly"))
                {
                    if (_r1.Contains(Stem.Length))
                    {
                        Stem = Stem.Substring(0, Stem.LastIndexOf("eed")) + "ee";
                    }
                }
                return;
            }

            // ed   edly+   ing   ingly+ - delete if the preceding word part contains a vowel, and then
            if ((Stem.EndsWith("ed") && Stem.IndexOfAny(Vowels, 0, Stem.Length - 2) != -1) ||
                (Stem.EndsWith("edly") && Stem.IndexOfAny(Vowels, 0, Stem.Length - 4) != -1) ||
                (Stem.EndsWith("ing") && Stem.IndexOfAny(Vowels, 0, Stem.Length - 3) != -1) ||
                (Stem.EndsWith("ingly") && Stem.IndexOfAny(Vowels, 0, Stem.Length - 5) != -1))
            {
                StripEnding(new string[4] {
                    "ed", "edly", "ing", "ingly"
                });
                // if the word ends at, bl or iz add e (so luxuriat -> luxuriate), or
                if (Stem.EndsWith("at") ||
                    Stem.EndsWith("bl") ||
                    Stem.EndsWith("iz"))
                {
                    Stem += "e";
                    return;
                }
                // if the word ends with a double remove the last letter (so hopp -> hop), or
                string end2chars;
                if (Stem.Length >= 2)
                {
                    end2chars = Stem.Substring(Stem.Length - 2, 2);
                }
                else
                {
                    return;
                }

                var doubleEndings = new List <string>(DoubleChars);
                if (doubleEndings.Contains(end2chars))
                {
                    Stem = Stem.Remove(Stem.Length - 1);
                    return;
                }
                // if the word is short, add e (so hop -> hope)
                if (IsShortWord())
                {
                    Stem += "e";
                    return;
                }
            }
        }
Пример #2
0
 private bool IsValidLIEnding()
 {
     if (Stem.Length > 2)
     {
         string preLi = Stem.Substring(Stem.Length - 3, 1);
         return(ValidLIEnding.Contains(preLi));
     }
     return(false);
 }
Пример #3
0
 /// <summary>
 /// replace suffix y or Y by i if preceded by a non-vowel which is not the first letter of the word (so cry -> cri, by -> by, say -> say)
 /// </summary>
 internal void ReplaceSuffixStep1c()
 {
     //replace suffix y or Y by i if preceded by a non-vowel which is not the first letter of the word (so cry -> cri, by -> by, say -> say)
     if (Stem.EndsWith("y", StringComparison.OrdinalIgnoreCase) &&
         (Stem.Length > 2) &&
         (Stem.IndexOfAny(Vowels, Stem.Length - 2) != Stem.Length - 2))
     {
         Stem = Stem.Substring(0, Stem.Length - 1) + "i";
     }
 }
Пример #4
0
        /// <summary>
        /// Handle the three forms of closing apostrophe
        /// </summary>
        internal void StripTrailingApostrophe()
        {
            if (Stem.EndsWith("'s'"))
            {
                Stem = Stem.Substring(0, Stem.Length - 3);
                return;
            }

            if (Stem.EndsWith("'s"))
            {
                Stem = Stem.Substring(0, Stem.Length - 2);
                return;
            }

            if (Stem.EndsWith("'"))
            {
                Stem = Stem.Substring(0, Stem.Length - 1);
                return;
            }
        }
Пример #5
0
        /// <summary>
        /// Search for the longest among the following suffixes, and perform the action indicated.
        ///	sses
        ///		replace by ss
        ///
        ///	ied+   ies*
        ///		replace by i if preceded by more than one letter, otherwise by ie (so ties -> tie, cries -> cri)
        ///
        ///	s
        ///		delete if the preceding word part contains a vowel not immediately before the s (so gas and this retain the s, gaps and kiwis lose it)
        ///
        ///	us+   ss
        ///		do nothing
        /// </summary>
        internal void StripSuffixStep1a()
        {
            //sses - replace by ss
            if (Stem.EndsWith("sses"))
            {
                Stem = Stem.Substring(0, Stem.Length - 2);                 //4 to remove sses -2 to re-introduce ss
                return;
            }

            //ied+   ies* - replace by i if preceded by more than one letter, otherwise by ie (so ties -> tie, cries -> cri)
            if (Stem.EndsWith("ies") ||
                Stem.EndsWith("ied"))
            {
                if (Stem.Length > 4)
                {
                    Stem = Stem.Substring(0, Stem.Length - 2);
                }
                else
                {
                    Stem = Stem.Substring(0, Stem.Length - 1);
                }
                return;
            }

            //us+   ss - do nothing
            if (Stem.EndsWith("us") ||
                Stem.EndsWith("ss"))
            {
                return;
            }

            //s  - delete if the preceding word part contains a vowel not immediately
            //		before the s (so gas and this retain the s, gaps and kiwis lose it)
            if (Stem.EndsWith("s") &&
                Stem.Length > 2 &&
                Stem.Substring(0, Stem.Length - 2).IndexOfAny(Vowels) > -1)
            {
                Stem = Stem.Substring(0, Stem.Length - 1);
                return;
            }
        }
Пример #6
0
        /// <summary>
        /// Step 2:
        ///Search for the longest among the following suffixes, and, if found and in R1, perform the action indicated.
        ///
        ///tional:   replace by tion
        ///enci:   replace by ence
        ///anci:   replace by ance
        ///abli:   replace by able
        ///entli:   replace by ent
        ///izer   ization:   replace by ize
        ///ational   ation   ator:   replace by ate
        ///alism   aliti   alli:   replace by al
        ///fulness:   replace by ful
        ///ousli   ousness:   replace by ous
        ///iveness   iviti:   replace by ive
        ///biliti   bli+:   replace by ble
        ///ogi+:   replace by og if preceded by l
        ///fulli+:   replace by ful
        ///lessli+:   replace by less
        ///li+:   delete if preceded by a valid li-ending
        /// </summary>
        internal void ReplaceEndingStep2()
        {
            //Step 2:
            //Search for the longest among the following suffixes, and, if found and in R1, perform the action indicated.

            if (EndsWithAndInR1("ational"))
            {
                //7 ational   ation   ator:   replace by ate
                Stem = Stem.Substring(0, Stem.Length - 7) + "ate";
                return;
            }
            ;
            if (EndsWithAndInR1("fulness"))
            {
                //7 fulness:   replace by ful
                Stem = Stem.Substring(0, Stem.Length - 7) + "ful";
                return;
            }
            ;
            if (EndsWithAndInR1("iveness"))
            {
                //7 iveness   iviti:   replace by ive
                Stem = Stem.Substring(0, Stem.Length - 7) + "ive";
                return;
            }
            ;
            if (EndsWithAndInR1("ization"))
            {
                //7 izer   ization:   replace by ize
                Stem = Stem.Substring(0, Stem.Length - 7) + "ize";
                return;
            }
            ;
            if (EndsWithAndInR1("ousness"))
            {
                //7 ousli   ousness:   replace by ous
                Stem = Stem.Substring(0, Stem.Length - 7) + "ous";
                return;
            }
            ;
            if (EndsWithAndInR1("biliti"))
            {
                //6 biliti   bli+:   replace by ble
                Stem = Stem.Substring(0, Stem.Length - 6) + "ble";
                return;
            }
            ;
            if (EndsWithAndInR1("lessli"))
            {
                //6 lessli+:   replace by less
                Stem = Stem.Substring(0, Stem.Length - 6) + "less";
                return;
            }
            ;
            if (EndsWithAndInR1("tional"))
            {
                //6 tional:   replace by tion
                Stem = Stem.Substring(0, Stem.Length - 6) + "tion";
                return;
            }
            ;
            if (EndsWithAndInR1("alism"))
            {
                //5 alism   aliti   alli:   replace by al
                Stem = Stem.Substring(0, Stem.Length - 5) + "al";
                return;
            }
            ;
            if (EndsWithAndInR1("aliti"))
            {
                //5 alism   aliti   alli:   replace by al
                Stem = Stem.Substring(0, Stem.Length - 5) + "al";
                return;
            }
            ;
            if (EndsWithAndInR1("ation"))
            {
                //5 ational   ation   ator:   replace by ate
                Stem = Stem.Substring(0, Stem.Length - 5) + "ate";
                return;
            }
            ;
            if (EndsWithAndInR1("entli"))
            {
                //5 entli:   replace by ent
                Stem = Stem.Substring(0, Stem.Length - 5) + "ent";
                return;
            }
            ;
            if (EndsWithAndInR1("fulli"))
            {
                //5 fulli+:   replace by ful
                Stem = Stem.Substring(0, Stem.Length - 5) + "ful";
                return;
            }
            ;
            if (EndsWithAndInR1("iviti"))
            {
                //5 iveness   iviti:   replace by ive
                Stem = Stem.Substring(0, Stem.Length - 5) + "ive";
                return;
            }
            ;
            if (EndsWithAndInR1("ousli"))
            {
                //5 ousli   ousness:   replace by ous
                Stem = Stem.Substring(0, Stem.Length - 5) + "ous";
                return;
            }
            ;
            if (EndsWithAndInR1("abli"))
            {
                //4 abli:   replace by able
                Stem = Stem.Substring(0, Stem.Length - 4) + "able";
                return;
            }
            ;
            if (EndsWithAndInR1("alli"))
            {
                //4 alism   aliti   alli:   replace by al
                Stem = Stem.Substring(0, Stem.Length - 4) + "al";
                return;
            }
            ;
            if (EndsWithAndInR1("anci"))
            {
                //4 anci:   replace by ance
                Stem = Stem.Substring(0, Stem.Length - 4) + "ance";
                return;
            }
            ;
            if (EndsWithAndInR1("ator"))
            {
                //5 ational   ation   ator:   replace by ate
                Stem = Stem.Substring(0, Stem.Length - 4) + "ate";
                return;
            }
            ;
            if (EndsWithAndInR1("enci"))
            {
                //4 enci:   replace by ence
                Stem = Stem.Substring(0, Stem.Length - 4) + "ence";
                return;
            }
            ;
            if (EndsWithAndInR1("izer"))
            {
                //4 izer   ization:   replace by ize
                Stem = Stem.Substring(0, Stem.Length - 4) + "ize";
                return;
            }
            ;
            if (EndsWithAndInR1("bli"))
            {
                //3 biliti   bli+:   replace by ble
                Stem = Stem.Substring(0, Stem.Length - 3) + "ble";
                return;
            }
            ;
            if (EndsWithAndInR1("ogi"))
            {
                //3 ogi+:   replace by og if preceded by l
                Stem = Stem.Substring(0, Stem.Length - 3) + "og";
                return;
            }
            ;
            if (EndsWithAndInR1("li") &&
                IsValidLIEnding())
            {
                //2 li+:   delete if preceded by a valid li-ending
                Stem = Stem.Substring(0, Stem.Length - 2);
                return;
            }
            ;
        }
Пример #7
0
        /// <summary>
        /// Step 3:
        ///Search for the longest among the following suffixes, and, if found and in R1, perform the action indicated.
        ///
        ///tional+:   replace by tion
        ///ational+:   replace by ate
        ///alize:   replace by al
        ///icate   iciti   ical:   replace by ic
        ///ful   ness:   delete
        ///ative*:   delete if in R2
        /// </summary>
        internal void ReplaceEndingStep3()
        {
            //ational+:   replace by ate
            if (EndsWithAndInR1("ational"))
            {
                Stem = Stem.Substring(0, Stem.Length - 5) + "e";
                return;
            }
            ;
            //tional+:   replace by tion
            if (EndsWithAndInR1("tional"))
            {
                Stem = Stem.Substring(0, Stem.Length - 2);
                return;
            }
            ;
            //alize:   replace by al
            if (EndsWithAndInR1("alize"))
            {
                Stem = Stem.Substring(0, Stem.Length - 3);
                return;
            }
            ;
            //ative*:   delete if in R2
            if (EndsWithAndInR2("ative"))
            {
                Stem = Stem.Substring(0, Stem.Length - 5);
                return;
            }
            ;
            //icate  :   replace by ic
            //iciti :   replace by ic
            if (EndsWithAndInR1("icate") || EndsWithAndInR1("iciti"))
            {
                Stem = Stem.Substring(0, Stem.Length - 3);
                return;
            }
            ;
            //ical:   replace by ic
            if (EndsWithAndInR1("ical"))
            {
                Stem = Stem.Substring(0, Stem.Length - 2);
                return;
            }
            ;

            //   ness:   delete
            if (EndsWithAndInR1("ness"))
            {
                Stem = Stem.Substring(0, Stem.Length - 4);
                return;
            }
            ;
            //ful   :   delete
            if (EndsWithAndInR1("ful"))
            {
                Stem = Stem.Substring(0, Stem.Length - 3);
                return;
            }
            ;
        }