-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchi_square_to_csv.py
80 lines (59 loc) · 1.97 KB
/
chi_square_to_csv.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
import json
import csv
from itertools import zip_longest
with open('chi_square_dicts/chi_dict_plus.json', 'r', encoding='utf-8') as f:
words_plus = json.load(f)
with open('chi_square_dicts/chi_dict_minus.json', 'r', encoding='utf-8') as f:
words_minus = json.load(f)
with open('chi_square_dicts/chi_dict_collocations_plus.json', 'r', encoding='utf-8') as f:
collocations_plus = json.load(f)
with open('chi_square_dicts/chi_dict_collocations_minus.json', 'r', encoding='utf-8') as f:
collocations_minus = json.load(f)
keys = []
answers = []
for words in words_plus:
keys.append(words[0])
answers.append(words[1])
d = [keys, answers]
export_data = zip_longest(*d, fillvalue='')
with open('chi_square_dicts/dictionary_plus.csv', 'w', encoding='utf-8', newline='') as f:
wr = csv.writer(f)
wr.writerow(("term", "chi_square"))
wr.writerows(export_data)
f.close()
keys = []
answers = []
for words in words_minus:
keys.append(words[0])
answers.append(words[1])
d = [keys, answers]
export_data = zip_longest(*d, fillvalue='')
with open('chi_square_dicts/dictionary_minus.csv', 'w', encoding='utf-8', newline='') as f:
wr = csv.writer(f)
wr.writerow(("term", "chi_square"))
wr.writerows(export_data)
f.close()
keys = []
answers = []
for words in collocations_plus:
keys.append(words[0])
answers.append(words[1])
d = [keys, answers]
export_data = zip_longest(*d, fillvalue='')
with open('chi_square_dicts/collocations_plus.csv', 'w', encoding='utf-8', newline='') as f:
wr = csv.writer(f)
wr.writerow(("term", "chi_square"))
wr.writerows(export_data)
f.close()
keys = []
answers = []
for words in collocations_minus:
keys.append(words[0])
answers.append(words[1])
d = [keys, answers]
export_data = zip_longest(*d, fillvalue='')
with open('chi_square_dicts/collocations_minus.csv', 'w', encoding='utf-8', newline='') as f:
wr = csv.writer(f)
wr.writerow(("term", "chi_square"))
wr.writerows(export_data)
f.close()