Parse a Chinese syllable and return its basic structure.

def parse_chinese_morphemes(seq, context=False):
    """
    Parse a Chinese syllable and return its basic structure. 
    """
    
    # get the tokens
    if isinstance(seq, list):
        tokens = [s for s in seq]
    else:
        tokens = lingpy.ipa2tokens(seq, merge_vowels=False)
    
    # get the sound classes according to the art-model
    arts = [int(x) for x in lingpy.tokens2class(tokens, _art, cldf=True)]

    # get the pro-string
    prostring = lingpy.prosodic_string(arts)

    # parse the zip of tokens and arts
    I,M,N,C,T = '','','','',''
    
    ini = False
    med = False
    nuc = False
    cod = False
    ton = False
    
    triples = [('?','?','?')]+list(zip(
        tokens,arts,prostring))+[('?','?','?')]

    for i in range(1,len(triples)-1): #enumerate(triples[1:-1]): #zip(tokens,arts,prostring):
        
        t,c,p = triples[i]
        _t,_c,_p = triples[i-1]
        t_,c_,p_ = triples[i+1]

        # check for initial entry first
        if p == 'A' and _t == '?':

            # now, if we have a j-sound and a vowel follows, we go directly to
            # medial environment
            if t[0] in 'jɥw':
                med = True
                ini,nuc,cod,ton = False,False,False,False
            else:
                ini = True
                med,nuc,doc,ton = False,False,False,False
        
        # check for initial vowel
        elif p == 'X' and _t == '?':
            if t[0] in 'iuy' and c_ == '7':
                med = True
                ini,nuc,cod,ton = False,False,False,False
            else:
                nuc = True
                ini,med,cod,ton = False,False,False,False

        # check for medial after initial
        elif p == 'C':
            med = True
            ini,nuc,cod,ton = False,False,False,False

        # check for vowel medial 
        elif p == 'X' and p_ == 'Y':
            
            # if we have a medial vowel, we classify it as medial
            if t in 'iyu':
                med = True
                ini,nuc,cod,ton = False,False,False,False
            else:
                nuc = True
                ini,med,cod,ton = False,False,False,False

        # check for vowel without medial
        elif p == 'X' or p == 'Y':
            if p_ in 'LTY' or p_ == '?':
                nuc = True
                ini,med,cod,ton = False,False,False,False
            elif p == 'Y':
                nuc = True
                ini,med,cod,ton = 4 * [False]
            else:
                cod = True
                ini,med,nuc,ton = 4 * [False]
        
        # check for consonant
        elif p == 'L':
            cod = True
            ini,med,nuc,ton = 4 * [False]

        # check for tone
        elif p == 'T':
            ton = True
            ini,med,nuc,cod = 4 * [False]

        if ini:
            I += t
        elif med:
            M += t
        elif nuc:
            N += t
        elif cod:
            C += t
        else:
            T += t
    
    # bad conversion for output, but makes what it is supposed to do
    out = [I,M,N,C,T]
    tf = lambda x: x if x else '-'
    out = [tf(x) for x in out]
    
    # transform tones to normal letters
    tones = dict(zip('¹²³⁴⁵⁶⁷⁸⁹⁰₁₂₃₄₅₆₇₈₉₀','1234567890123456789'))

    # now, if context is wanted, we'll yield that
    ic = '1' if [x for x in I if x in 'bdgmnŋȵɳɴ'] else '0'
    mc = '1' if [m for m in M+N if m in 'ijyɥ'] else '0'
    cc = '1' if C in 'ptkʔ' else '0'
    tc = ''.join([tones.get(x, x) for x in T])

    IC = '/'.join(['I',ic,mc,cc,tc]) if I else ''
    MC = '/'.join(['M',ic,mc,cc,tc]) if M else ''
    NC = '/'.join(['N',ic,mc,cc,tc]) if N else ''
    CC = '/'.join(['C',ic,mc,cc,tc]) if C else ''
    TC = '/'.join(['T',ic,mc,cc,tc]) if T else ''

    if context:
        return out, [x for x in [IC,MC,NC,CC,TC] if x]
    return out