Пример #1
0
        private static void Step2(StringBuilder word, StemRegion stemRegion)
        {
            var replacement = word.EndsWith(step2Replacements);
            var length      = word.Length;

            if (replacement.MatchWord != null && length - replacement.MatchWord.Length >= stemRegion.R1)
            {
                switch (replacement.MatchWord)
                {
                case "OGI":
                    if (length > 3 && word[length - replacement.MatchWord.Length - 1] == 'L')
                    {
                        word.ReplaceEnd(replacement);
                    }

                    break;

                case "LI":
                    if (length > 1 && IsRemovableLiEnding(word[length - 3]))
                    {
                        word.Length -= 2;
                    }

                    break;

                default:
                    word.ReplaceEnd(replacement);
                    break;
                }
            }
        }
Пример #2
0
        private static void Step1b(StringBuilder word, StemRegion stemRegion)
        {
            var replacement = word.EndsWith(step1bReplacements);
            var matchedWord = replacement.MatchWord;

            if (matchedWord != null)
            {
                switch (matchedWord)
                {
                case "EEDLY":
                case "EED":
                    if (word.Length - matchedWord.Length >= stemRegion.R1)
                    {
                        word.ReplaceEnd(replacement);
                    }

                    break;

                default:
                    var found = false;
                    for (var j = 0; j < word.Length - matchedWord.Length; ++j)
                    {
                        if (word.IsVowel(j))
                        {
                            word.ReplaceEnd(replacement);
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        if (word.EndsWith(step1bAppendEEndings) != null)
                        {
                            word.Append('E');
                        }
                        else if (HasDoubleLetterEnding(word))
                        {
                            word.Length -= 1;
                        }
                        else if (word.IsShortWord(stemRegion))
                        {
                            word.Append('E');
                        }
                    }

                    break;
                }
            }
        }
Пример #3
0
        private static void Step4(StringBuilder word, StemRegion stemRegion)
        {
            var replacement = word.EndsWith(step4Replacements);

            if (replacement.MatchWord != null && word.Length - replacement.MatchWord.Length >= stemRegion.R2)
            {
                if (replacement.MatchWord == "ION")
                {
                    if (word.Length > 3 && IsRemovableIonEnding(word[word.Length - 4]))
                    {
                        word.Length -= replacement.MatchWord.Length;
                    }
                }
                else
                {
                    word.Length -= replacement.MatchWord.Length;
                }
            }
        }
Пример #4
0
        private static void Step3(StringBuilder word, StemRegion stemRegion)
        {
            var replacement = word.EndsWith(step3Replacements);

            if (replacement.MatchWord != null && word.Length - replacement.MatchWord.Length >= stemRegion.R1)
            {
                if (replacement.MatchWord == "ATIVE")
                {
                    if (word.Length - replacement.MatchWord.Length >= stemRegion.R2)
                    {
                        word.ReplaceEnd(replacement);
                    }
                }
                else
                {
                    word.ReplaceEnd(replacement);
                }
            }
        }
Пример #5
0
        private static void Step5(StringBuilder word, StemRegion stemRegion)
        {
            var length = word.Length;

            if (length == 0)
            {
                return;
            }

            if (word[length - 1] == 'E' &&
                (length - 1 >= stemRegion.R2 || (length - 1 >= stemRegion.R1 && !word.IsShortSyllable(length - 3))))
            {
                word.Length -= 1;
            }
            else if (length - 1 >= stemRegion.R2 && word.EndsWith("LL"))
            {
                word.Length -= 1;
            }
        }
Пример #6
0
 /// <summary>
 /// Determines whether the word in the string builder is a short word.
 /// </summary>
 /// <param name="builder">The builder to analyse.</param>
 /// <param name="region">The calculated stem region for the word.</param>
 /// <returns>
 ///     <c>true</c> if the word is a short word; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsShortWord(this StringBuilder builder, StemRegion region)
 {
     return(region.R1 >= builder.Length && builder.IsShortSyllable(builder.Length - 2));
 }