示例#1
0
    def add_ending(self, ending=u""):
        """ Add an ending to the word, combining vowel-consonant
        pairs if necessary """

        # If ending begins with a vowel, the word must end with a consonant
        # and this consonant-vowel pair should be combined
        # If the word doesn't end with a consonant, raise a value error
        if TamilLetter.is_vowel(ending[0]):

            if TamilLetter.is_consonant(self.word[-1]):

                # replace the last letter of the word with the consonant-vowel
                # combination, then copy over the rest of the ending
                self.word[-1] = TamilLetter.get_combination(self.word[-1], ending[0])
                self.word += ending[1:]

            # Unless word ends with a consonant, ending cannot start with a vowel
            else:
                raise ValueError(
                    """Invalid word-ending pair - ending
                    can only start with a vowel if word ends with consonant"""
                )

        # In all other cases, simply add the ending to the word
        self.word += ending
示例#2
0
    def split_syllables(letters=[]):
        """ Returns the syllables in a given word as a list """

        # Generic algorithm:
        # Each vowel and combination is its own syllable. Consonants and
        # aytham get added to the end of the previous syllable

        # ensure that the word is a valid word
        TamilWord.validate("".join(letters))

        # initialize empty list
        syllables = []

        # loop through letters in the word
        for letter in letters:

            # if letter is a vowel or combination, it gets its own syllable
            if TamilLetter.is_combination(letter) or TamilLetter.is_vowel(letter):
                syllables.append(letter)

            # if codepoint is a consonant or aytham, add it to the end
            # of the previously-added codepoint
            elif TamilLetter.is_consonant(letter) or TamilLetter.is_aytham(letter):

                # ensure that at least one character already exists
                if len(syllables) > 0:
                    syllables[-1] = syllables[-1] + letter

                # if the first letter is a consonant (probably b/c it' s a
                # loanword), add it to the beginning of the string
                else:
                    syllables.append(letter)

            # if codepoint was neither a vowel, aytham, a pulli or a
            # combination ending, an unexpected error has occurred
            else:
                raise Exception(
                    """Unknown error: \'%s\' in word %s is neither
                 a vowel, consonant, combination or aytham"""
                    % (letter, "".join(letters))
                )

        return syllables
示例#3
0
    def split_syllables(letters=[]):
        """ Returns the syllables in a given word as a list """

        # Generic algorithm:
        # Each vowel and combination is its own syllable. Consonants and
        # aytham get added to the end of the previous syllable

        # ensure that the word is a valid word
        TamilWord.validate(''.join(letters))

        # initialize empty list
        syllables = []

        # loop through letters in the word
        for letter in letters:

            # if letter is a vowel or combination, it gets its own syllable
            if TamilLetter.is_combination(letter) or \
                TamilLetter.is_vowel(letter):
                syllables.append(letter)

            # if codepoint is a consonant or aytham, add it to the end
            # of the previously-added codepoint
            elif TamilLetter.is_consonant(letter) or \
                TamilLetter.is_aytham(letter):

                # ensure that at least one character already exists
                if len(syllables) > 0:
                    syllables[-1] = syllables[-1] + letter

                # if the first letter is a consonant (probably b/c it' s a
                # loanword), add it to the beginning of the string
                else:
                    syllables.append(letter)

            # if codepoint was neither a vowel, aytham, a pulli or a
            # combination ending, an unexpected error has occurred
            else:
                raise Exception("""Unknown error: \'%s\' in word %s is neither
                 a vowel, consonant, combination or aytham""" %
                                (letter, ''.join(letters)))
示例#4
0
    def add_ending(self, ending=''):
        """ Add an ending to the word, combining vowel-consonant
        pairs if necessary """

        # If ending begins with a vowel, the word must end with a consonant
        # and this consonant-vowel pair should be combined
        # If the word doesn't end with a consonant, raise a value error
        if TamilLetter.is_vowel(ending[0]):

            if TamilLetter.is_consonant(self.word[-1]):

                # replace the last letter of the word with the consonant-vowel
                # combination, then copy over the rest of the ending
                self.word[-1] = TamilLetter.get_combination(self.word[-1], \
                                                            ending[0])
                self.word += ending[1:]

            # Unless word ends with a consonant, ending cannot start with a vowel
            else:
                raise ValueError("""Invalid word-ending pair - ending
                    can only start with a vowel if word ends with consonant""")

        # In all other cases, simply add the ending to the word
        self.word += ending