def fanqie2mch(fanqie, debug=False):
<EOL>fanqie = gbk2big5(fanqie)<EOL>shangxia = chars2baxter(fanqie)<EOL>if fanqie[<NUM_LIT:0>] in _cd.GY['<STR_LIT>']:<EOL><INDENT>shang = _cd.GY['<STR_LIT>'][fanqie[<NUM_LIT:0>]]+'<STR_LIT:a>'<EOL><DEDENT>else:<EOL><INDENT>shang = shangxia[<NUM_LIT:0>]<EOL><DEDENT>xia = shangxia[<NUM_LIT:1>]<EOL>if '<STR_LIT:U+0020>' in shang:<EOL><INDENT>shang = shang[:shang.index('<STR_LIT:U+0020>')]<EOL><DEDENT>if '<STR_LIT:U+0020>' in xia:<EOL><INDENT>xia = xia[:xia.index('<STR_LIT:U+0020>')]<EOL><DEDENT>if '<STR_LIT:U+002C>' in shang or '<STR_LIT:U+002C>' in xia or not shang or not xia:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(shang,xia))<EOL><DEDENT>shangp = parse_baxter(shang)<EOL>xiap = parse_baxter(xia)<EOL>if debug:<EOL><INDENT>return '<STR_LIT:.>'.join(shangp),'<STR_LIT:.>'.join(xiap),shang,xia<EOL><DEDENT>i = shangp[<NUM_LIT:0>]<EOL>m = xiap[<NUM_LIT:1>]<EOL>f = xiap[<NUM_LIT:2>]<EOL>t = xiap[<NUM_LIT:3>].replace('<STR_LIT:P>','<STR_LIT>').replace('<STR_LIT:R>','<STR_LIT>') <EOL>if ('<STR_LIT:y>' in i or '<STR_LIT:i>' in f) and '<STR_LIT>' in m:<EOL><INDENT>m = m.replace('<STR_LIT>','<STR_LIT>')<EOL><DEDENT>if '<STR_LIT:u>' in f and '<STR_LIT:w>' in m:<EOL><INDENT>m = m.replace('<STR_LIT:w>','<STR_LIT>')<EOL><DEDENT>return '<STR_LIT>'.join([i,m,f,t])<EOL>
Convert a Fǎnqiè reading to it's MCH counterpart.

Important: we need to identify the medials in the xia-syllable. We also
need to make additional background-checks, since in the current form, the
approach is not error-prone and does not what it is supposed to do!