-
Notifications
You must be signed in to change notification settings - Fork 1
/
rate.py
57 lines (46 loc) · 1.72 KB
/
rate.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from collections import defaultdict
from rich import print
import json
import os
gen = defaultdict(list)
with open("output.txt", "r") as f:
for line in f:
zi, code = line.split('\t')
gen[zi].append(code.strip())
flypy = {}
with open(os.path.join(os.path.dirname(__file__), 'flypy/小鹤音形单字全码码表.json'), 'r', encoding='utf-8') as f:
flypy = json.load(f)
xk_correct_count, full_correct_count = 0, 0
output = []
zis = []
for item in flypy:
code = item['fly_code'][0:4]
zi = item['character']
if zi not in gen:
print(f"{zi}: [yellow]missing {code}[/yellow]")
output.append(f"{zi}\t{code}\n")
zis.append(zi)
elif code not in gen[zi]:
音 = code[:2]
if not any(音 == c[:2] for c in gen[zi]):
print(
f"{zi}: 音码错误, expected [green]{code}[/green] but got [medium_orchid]{' / '.join(gen[zi])}[/medium_orchid]"
)
xk_correct_count += 1
else:
print(
f"{zi}: 形码错误, expected [green]{code}[/green] but got [red]{' / '.join(gen[zi])}[/red]"
)
output.append(f"{zi}\t{code}\n")
zis.append(zi)
else:
full_correct_count += 1
xk_correct_count += 1
total = len(flypy)
print(f"[green]{xk_correct_count}[/green] / [blue]{total}[/blue] total,",
f"[pink]{xk_correct_count/total*100:.2f}%[/pink]")
print(f"[green]{full_correct_count}[/green] / [blue]{total}[/blue] total,",
f"[pink]{full_correct_count/total*100:.2f}%[/pink]")
with open("查漏补缺.txt", "w") as f:
f.writelines(output)
print("错误或缺失的字:[red]" + "".join(zis) + "[/red]")