-
Notifications
You must be signed in to change notification settings - Fork 10
/
compile_zht_dict.py
45 lines (36 loc) · 1007 Bytes
/
compile_zht_dict.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
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import re
import sys
import math
import random
import string
import textwrap
import itertools
import unicodedata
import collections
zht_chars = collections.OrderedDict()
for filename in ('wordlist/tw_cygzb.txt', 'wordlist/tw_ccygzb.txt', 'wordlist/hk_cyzzxb.txt'):
with open(filename, 'r', encoding='utf-8') as f:
zht_chars.update({unicodedata.normalize('NFKC', x.strip()): 0
for x in f.readlines()})
with open('wordlist/charfreq_zht.txt') as f:
for ln in f:
row = ln.strip().split()
if len(row) < 2:
continue
word, freq = row
if word in zht_chars:
zht_chars[word] = int(freq)
sorted_chars = sorted(zht_chars.items(), key=lambda x: -x[1])
last_freq = None
for i, (ch, freq) in enumerate(sorted_chars):
if i >= 8500:
if freq == last_freq:
print(ch)
else:
break
else:
last_freq = freq
print(ch)