# Path: pypinyin/contrib/tone_convert.py



import re
from pypinyin.contrib.tone_convert import tone_to_tone2, tone2_to_tone
        ret = super(ToneSandhiMixin, self).post_pinyin(
            han, heteronym, pinyin_list, **kwargs)
        if ret is not None:
            pinyin_list = ret

        pinyin_list = self._third_tone(han, pinyin_list)
        pinyin_list = self._bu(han, pinyin_list)
        pinyin_list = self._yi(han, pinyin_list)

        return pinyin_list

    def _third_tone(self, han, pinyin_list):
        """

        Third tone sandhi:

        The principal rule of third tone sandhi is:

            When there are two consecutive third-tone syllables, the first of them is pronounced with second tone.

        For example, lǎoshǔ 老鼠 ("mouse") comes to be pronounced láoshǔ [lau̯˧˥ʂu˨˩]. It has been investigated whether the rising contour (˧˥) on the prior syllable is in fact identical to a normal second tone; it has been concluded that it is, at least in terms of auditory perception.[1]: 237 

        When there are three or more third tones in a row, the situation becomes more complicated, since a third tone that precedes a second tone resulting from third tone sandhi may or may not be subject to sandhi itself. The results may depend on word boundaries, stress, and dialectal variations. General rules for three-syllable third-tone combinations can be formulated as follows:

            If the first word is two syllables and the second word is one syllable, then the first two syllables become second tones. For example, bǎoguǎn hǎo 保管好 ("to take good care of") takes the pronunciation báoguán hǎo [pau̯˧˥kwan˧˥xau̯˨˩˦].
            If the first word is one syllable, and the second word is two syllables, the second syllable becomes second tone, but the first syllable remains third tone. For example: lǎo bǎoguǎn 老保管 ("to take care of all the time") takes the pronunciation lǎo báoguǎn [lau̯˨˩pau̯˧˥kwan˨˩˦].

        Some linguists have put forward more comprehensive systems of sandhi rules for multiple third tone sequences. For example, it is proposed[1]: 248  that modifications are applied cyclically, initially within rhythmic feet (trochees; see below), and that sandhi "need not apply between two cyclic branches".

        """  # noqa

# Path: pypinyin/contrib/tone_convert.py



# Path: pypinyin/contrib/tone_sandhi.py
import re
from pypinyin.contrib.tone_convert import tone_to_tone2, tone2_to_tone

        ret = super(ToneSandhiMixin, self).post_pinyin(
            han, heteronym, pinyin_list, **kwargs)
        if ret is not None:
            pinyin_list = ret

        pinyin_list = self._third_tone(han, pinyin_list)
        pinyin_list = self._bu(han, pinyin_list)
        pinyin_list = self._yi(han, pinyin_list)

        return pinyin_list

    def _third_tone(self, han, pinyin_list):
        """

        Third tone sandhi:

        The principal rule of third tone sandhi is:

            When there are two consecutive third-tone syllables, the first of them is pronounced with second tone.

        For example, lǎoshǔ 老鼠 ("mouse") comes to be pronounced láoshǔ [lau̯˧˥ʂu˨˩]. It has been investigated whether the rising contour (˧˥) on the prior syllable is in fact identical to a normal second tone; it has been concluded that it is, at least in terms of auditory perception.[1]: 237 

        When there are three or more third tones in a row, the situation becomes more complicated, since a third tone that precedes a second tone resulting from third tone sandhi may or may not be subject to sandhi itself. The results may depend on word boundaries, stress, and dialectal variations. General rules for three-syllable third-tone combinations can be formulated as follows:

            If the first word is two syllables and the second word is one syllable, then the first two syllables become second tones. For example, bǎoguǎn hǎo 保管好 ("to take good care of") takes the pronunciation báoguán hǎo [pau̯˧˥kwan˧˥xau̯˨˩˦].
            If the first word is one syllable, and the second word is two syllables, the second syllable becomes second tone, but the first syllable remains third tone. For example: lǎo bǎoguǎn 老保管 ("to take care of all the time") takes the pronunciation lǎo báoguǎn [lau̯˨˩pau̯˧˥kwan˨˩˦].

        Some linguists have put forward more comprehensive systems of sandhi rules for multiple third tone sequences. For example, it is proposed[1]: 248  that modifications are applied cyclically, initially within rhythmic feet (trochees; see below), and that sandhi "need not apply between two cyclic branches".

        """  # noqa

        tone2_pinyin_list = [tone_to_tone2(x[0]) for x in pinyin_list]