Exemplo n.º 1
0
        private static ConsonantType GetConsonantType(char c)
        {
            if (!SyllablesService.IsConsonant(c))
            {
                throw new ArgumentException(string.Format("Char '{0}' is not a consonant.", c), "c");
            }

            if (SyllablesService.sonorouses.Contains(c))
            {
                return(ConsonantType.Sonorous);
            }

            return(SyllablesService.sibilants.Contains(c) ? ConsonantType.Sibilant : ConsonantType.Obstruents);
        }
Exemplo n.º 2
0
        private static SyllableCuttingMode GetCuttingMode(string word, int index)
        {
            char firstChar  = word[index - 1] != 'ь' ? word[index - 1] : word[index - 2];
            char secondChar = word[index];

            // Rule #1
            if (index + 1 < word.Length)
            {
                char thirdChar = word[index + 1] != '\'' ? word[index + 1] : word[index + 2];

                if (SyllablesService.IsVowel(firstChar) && SyllablesService.IsConsonant(secondChar) &&
                    SyllablesService.IsVowel(thirdChar))
                {
                    return(SyllableCuttingMode.Next);
                }
            }

            if (SyllablesService.IsConsonant(firstChar) && SyllablesService.IsConsonant(secondChar))
            {
                // Rule #6
                if (firstChar == secondChar)
                {
                    return(SyllableCuttingMode.Current);
                }
                if (SyllablesService.GetConsonantType(firstChar) == SyllablesService.GetConsonantType(secondChar))
                {
                    // Rule #5
                    if (SyllablesService.GetConsonantType(firstChar) == ConsonantType.Sonorous)
                    {
                        return(SyllableCuttingMode.Next);
                    }
                    return(SyllableCuttingMode.Current);
                }
                if (SyllablesService.GetConsonantType(secondChar) == ConsonantType.Obstruents) // Rule #3
                {
                    return(SyllableCuttingMode.Next);
                }
                if (SyllablesService.GetConsonantType(secondChar) == ConsonantType.Sonorous) // Rule #4
                {
                    return(SyllableCuttingMode.Current);
                }
            }
            else if (SyllablesService.IsVowel(firstChar) && SyllablesService.IsVowel(secondChar))
            {
                return(SyllableCuttingMode.Next);
            }

            return(SyllableCuttingMode.Skip);
        }