-
Notifications
You must be signed in to change notification settings - Fork 13
/
quickdic.py
31 lines (28 loc) · 1006 Bytes
/
quickdic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf8 -*-
# Convert amis dict to quickdic format (amis-cmn)
# Cf. https://code.google.com/p/quickdic-dictionary/wiki/BuildDictionary
# vim: ts=4 et sw=4 sts=4
import sys
import json
import codecs
def quickdic():
dictionary = json.load(open("dict-amis.json"))
amis_cmn = codecs.open('amis-cmn.dicts.txt', 'w', 'utf8')
amis_en = codecs.open('amis-en.dicts.txt', 'w', 'utf8')
for word in dictionary:
title = word['title']
for het in word['heteronyms']:
for defs in het['definitions']:
if 'def' not in defs:
print "!!!!!", title
dx = defs['def']
ex = defs.get('example', [])
p2 = dx.find(u'\ufffb')
en = dx[2:p2]
zh = dx[p2+1:]
amis_cmn.write('\t'.join((title, zh)) + '\n')
amis_en.write('\t'.join((title, en)) + '\n')
amis_cmn.close()
amis_en.close()
if __name__ == '__main__':
quickdic()