-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstats.py
86 lines (65 loc) · 1.48 KB
/
stats.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
fname = 'data/nouns.txt'
categories = (
'none',
'0', '0+',
'1', '1+',
'2', '2+',
'3', '3+',
'4', '4+',
'5', '5+',
'6', '6+',
'7', '7+',
'8', '8+',
'9', '9+',
'?',
'block',
'other',
)
base_categories = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '?', 'block')
test_cases = [
'японоведение:4 a',
'абаз',
'ять:?',
'яхтовладелец:0 a',
]
# * start
# init stats
count = 0
stats = dict(((v, 0) for v in categories))
def get_category(line):
(word, *description) = line.split(':')
# print(word, description)
if not len(description):
return 'none'
(cat, *comments) = ''.join(description).split(' ')
if cat not in base_categories:
print(line, cat)
return 'other'
# else cat in base categories
if cat not in ('?', 'block') and len(comments):
cat += '+'
return cat
def process_case(s):
global count
cat = get_category(s)
if cat in stats:
stats[cat] += 1
else:
print(s, cat)
count += 1
def print_stats(data):
for cat, count in data.items():
if count:
print(f"{cat}: {count}")
usable = data['1'] + data['2'] + data['6']
print(f"\n---\nusable: {usable}")
def test():
for s in test_cases:
process_case(s)
print_stats(stats)
# * go!
# test()
# exit()
for line in open(fname, 'r', encoding='utf-8'):
process_case(line.strip())
print_stats(stats)