예제 #1
0
파일: phoseg.py 프로젝트: suizokukan/phoseg
    def init_from_a_list_of_names(self, list_of_names):
        """
                PhoSegObject.init_from_a_list_of_names

                * list_of_names : list of sound's description like
                  ["velar stop", "rounded vowel", ...]
        """
        #. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
        # list_of_sounds : list_of_names -> list of PhoneticSegment objects
        #. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

        list_of_sounds = []     # list of PhoneticSegment objects

        for element in list_of_names:

            if element != "":
                (phoneticsegment_obj,
                 success,
                 pending_keywords,
                 independant) = PhoneticSegment().init_by_name(element)

                # no phonetic segment can be dependant here.
                if not independant:
                    error_msg = "PhoSegObject.init_from_a_list_of_names"
                    error_msg += ": incoherent list of sound's names"
                    error_msg += ": "+str(list_of_names)
                    raise PhoSegError(error_msg)

                if not success:
                    self.initialization_ok = False
                    self.error_msg += str(element)+" : "+str(pending_keywords)

                else:
                    list_of_sounds.append( phoneticsegment_obj )

        #. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
        # syllabation and initialization.
        #. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
        Syllables.__init__( self )
        # pylint: disable=E1101
        # ("Instance of 'PhoSegObject' has no 'init_from_a_list_of_phonemes'")
        # There's something weird about Pylint here...
        self.init_from_a_list_of_phonemes( list_of_sounds )
예제 #2
0
파일: phoseg.py 프로젝트: suizokukan/phoseg
    def init_from_a_sipa_string(self, sipa_str):
        """
                PhoSegObject.init_from_a_sipa_string

                * sipa_str : SIPA string like "(r,oː,)(m,aː,)"
        """
        list_of_syllables = []

        for dict_syllable in SIPA( sipa_str = sipa_str ):

            new_syllable = Syllable()

            # ONSET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
            for kwords in dict_syllable['onset']:

                (phoneticsegment_obj,
                 success,
                 pending_keywords,
                 independant) = PhoneticSegment().init_by_name(kwords)

                if not success:
                    self.initialization_ok = False
                    self.error_msg += kwords+" : "+str(pending_keywords)

                new_syllable.onset.append( phoneticsegment_obj )

            # NUCLEUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

            # vowel_to_be_linked :
            #
            # if no vowel is expected, <vowel_to_be_linked> is empty;
            # conversely, <vowel_to_be_linked> is filled with the
            # PhoneticSegment object vowels waiting to be linked to a vowel.
            vowel_to_be_linked = []

            for kwords in dict_syllable['nucleus']:

                (phoneticsegment_obj,
                 success,
                 pending_keywords,
                 independant)= PhoneticSegment().init_by_name(kwords)

                len_new_syllable_nucleus = len(new_syllable.nucleus)
                is_a_vowel = phoneticsegment_obj.is_a_vowel()

                if not success:
                    self.initialization_ok = False
                    self.error_msg += kwords+" : "+str(pending_keywords)

                elif independant:
                    # the current element is independant

                    # vowel(s) waiting to be linked ?
                    if len(vowel_to_be_linked) != 0:
                        # one or more vowels are waiting to be linked to a vowel :

                        new_syllable.nucleus.append( phoneticsegment_obj )

                        if is_a_vowel:
                            # we link the vowel(s) to the current element :
                            for vowel in vowel_to_be_linked[::-1]:
                                new_syllable.nucleus[-1].maindata.insert(0, *vowel.maindata )

                            # we set the index <maindatatopindex> :
                            new_syllable.nucleus[-1].maindatatopindex = len(vowel_to_be_linked)

                            # no more waiting vowels :
                            # pylint: disable=E1101
                            # ("Instance of list has no 'clear' member")
                            # There's something weird about Pylint here...
                            vowel_to_be_linked.clear()

                        else:
                            # (error) e.g. "i̯p"
                            self.initialization_ok = False
                            self.error_msg += "can't link vowel(s) to a consonant"
                            self.error_msg += " ("+sipa_str+")"

                    else:
                        # no vowel(s) waiting to be linked :
                        new_syllable.nucleus.append( phoneticsegment_obj )

                else:
                    # the current element isn't independant :
                    if not is_a_vowel:
                        # the current element is a consonant (s̯) : we link
                        # this element to a precedent consonant.

                        if len_new_syllable_nucleus == 0:
                            # (error) e.g. : "s̯apa"
                            self.initialization_ok = False
                            self.error_msg += "not independant element at the beginning "
                            self.error_msg += "of the nucleus of the sipa string"
                            self.error_msg += " ("+sipa_str+")"

                        elif new_syllable.nucleus[-1].is_a_vowel():
                            # (error) e.g. : "as̯pa"
                            self.initialization_ok = False
                            self.error_msg += "not independant consonantic element"
                            self.error_msg += "linked to a preceding vowel"
                            self.error_msg += " ("+sipa_str+")"

                        else:
                            # (normal case) e.g : "ts̯apa"
                            new_syllable.nucleus[-1].maindata.extend( phoneticsegment_obj.maindata )

                    else:
                        # the current element is a vowel (i̯) : we link
                        # this element to a preceding or following vowel.
                        if len_new_syllable_nucleus != 0 and \
                          new_syllable.nucleus[-1].is_a_vowel():

                            # we can link this vowel to the preceding one :
                            # e.g. "ai̯"
                            new_syllable.nucleus[-1].maindata.extend( phoneticsegment_obj.maindata )

                        else:
                            # we have to link this vowel to a following one :
                            vowel_to_be_linked.append( phoneticsegment_obj )

            # CODA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
            for kwords in dict_syllable['coda']:

                (phoneticsegment_obj,
                 success,
                 pending_keywords,
                 independant)= PhoneticSegment().init_by_name(kwords)

                if not success:
                    self.initialization_ok = False
                    self.error_msg += kwords+" : "+str(pending_keywords)

                new_syllable.coda.append( phoneticsegment_obj )

            list_of_syllables.append( new_syllable )

        #. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
        # initialization
        #. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
        Syllables.__init__( self )
        # pylint: disable=E1101
        # ("Instance of 'PhoSegObject' has no 'init_from_a_list_of_syllables'")
        # There's something weird about Pylint here...
        self.init_from_a_list_of_syllables( list_of_syllables )
예제 #3
0
파일: phoseg.py 프로젝트: suizokukan/phoseg
    def init_from_an_ipa_string(self, ipa_str):
        """
                PhoSegObject.init_from_an_ipa_string

                * ipa_str : IPA string like "roːmaː", NOT "[roːmaː]", NOT "/roːmaː/"
        """
        #. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
        # list_of_sounds : ipa_str -> list of names -> list of PhoneticSegment objects
        #. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
        list_of_sounds = []     # list of PhoneticSegment objects

        # if no vowel is expected, <vowel_to_be_linked> is empty;
        # conversely, <vowel_to_be_linked> is filled with the
        # PhoneticSegment object vowels waiting to be linked to a vowel.
        vowel_to_be_linked = []

        for name in IPA(ipa_str):

            (phoneticsegment_obj,
             success,
             pending_keywords,
             independant) = PhoneticSegment().init_by_name(name)

            is_a_vowel = phoneticsegment_obj.is_a_vowel()
            len_of_list_of_sounds = len(list_of_sounds)

            if not success:
                self.initialization_ok = False
                self.error_msg += name+" : "+str(pending_keywords)

            else:
                if independant:
                    # the current element is independant

                    # vowel(s) waiting to be linked ?
                    if len(vowel_to_be_linked) != 0:
                        # one or more vowels are waiting to be linked to a vowel :

                        if is_a_vowel:
                            # we link the vowel(s) to the current element :
                            for vowel in vowel_to_be_linked[::-1]:
                                phoneticsegment_obj.maindata.insert(0, *vowel.maindata )

                            # we add the current modified element :
                            list_of_sounds.append( phoneticsegment_obj )

                            # we set the index <maindatatopindex> :
                            phoneticsegment_obj.maindatatopindex = len(vowel_to_be_linked)

                            # no more waiting vowels :
                            # pylint: disable=E1101
                            # ("Instance of list has no 'clear' member")
                            # There's something weird about Pylint here...
                            vowel_to_be_linked.clear()

                        else:
                            # (error) e.g. "i̯p"
                            self.initialization_ok = False
                            self.error_msg += "can't link vowel(s) to a consonant"
                            self.error_msg += " ("+ipa_str+")"

                    else:
                        # no vowel(s) waiting to be linked :
                        list_of_sounds.append( phoneticsegment_obj )

                else:
                    # the current element isn't independant :
                    if not is_a_vowel:
                        # the current element is a consonant (s̯) : we link
                        # this element to a precedent consonant.

                        if len_of_list_of_sounds == 0:
                            # (error) e.g. : "s̯apa"
                            self.initialization_ok = False
                            self.error_msg += "not independant element at the beginning "
                            self.error_msg += "of the ipa string"
                            self.error_msg += " ("+ipa_str+")"

                        elif list_of_sounds[-1].is_a_vowel():
                            # (error) e.g. : "as̯pa"
                            self.initialization_ok = False
                            self.error_msg += "not independant consonantic element"
                            self.error_msg += "linked to a preceding vowel"
                            self.error_msg += " ("+ipa_str+")"

                        else:
                            # (normal case) e.g : "ts̯apa"
                            list_of_sounds[-1].maindata.extend( phoneticsegment_obj.maindata )

                    else:
                        # the current element is a vowel (i̯) : we link
                        # this element to a preceding or following vowel.
                        if len_of_list_of_sounds != 0 and \
                          list_of_sounds[-1].is_a_vowel():

                            # we can link this vowel to the preceding one :
                            # e.g. "ai̯"
                            list_of_sounds[-1].maindata.extend( phoneticsegment_obj.maindata )

                        else:
                            # we have to link this vowel to a following one :
                            vowel_to_be_linked.append( phoneticsegment_obj )

        if len(vowel_to_be_linked) != 0:
            self.initialization_ok = False
            self.error_msg += "don'k know how to link the following vowel(s) "
            self.error_msg += " ("+str(vowel_to_be_linked)+")"

        #. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
        # syllabation and initialization.
        #. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
        Syllables.__init__( self )
        # pylint: disable=E1101
        # ("Instance of 'PhoSegObject' has no 'init_from_a_list_of_phonemes'")
        # There's something weird about Pylint here...
        self.init_from_a_list_of_phonemes( list_of_sounds )