Files
uiuc-ece391-mp3/helpers/chinese-pinyin.ipynb

67 lines
1.5 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"py = {}\n",
"with open('hzpy-utf8.txt') as f:\n",
" while True:\n",
" d = f.readline()\n",
" if not d:\n",
" break\n",
" d = d.split(',')\n",
" if d[1] not in py:\n",
" py[d[1]] = []\n",
" py[d[1]].append(d[4])"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"with open('chinese-pinyin.txt', 'w') as f:\n",
" i = 0\n",
" ids = []\n",
" ks = list(py.keys())\n",
" ks = sorted(ks)\n",
" for k in ks:\n",
" l = 0\n",
" for w in py[k]:\n",
" i += 1\n",
" l += 1\n",
" f.write('0x%s,' % w)\n",
" f.write('\\n')\n",
" ids.append((k, i - l, l))\n",
" for k in ids:\n",
" f.write('{\"%s\",%d,%d},\\n' % (k[0], k[1], k[2]))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}