-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.py
157 lines (123 loc) · 4.48 KB
/
scanner.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import matplotlib.pyplot as plt
import pdfplumber
import glob
import numpy as np
from tqdm import tqdm
counter = {
'qald' : 0,
'lc-quad': 0,
'webquestionssp': 0,
'complexwebquestions': 0,
'cfq': 0,
'simplequestions': 0,
'webquestions': 0,
'complexquestions': 0,
'metaqa': 0,
'countries': 0,
'wn18rr': 0,
'kinship': 0,
'nell-995': 0,
'fb15k-237': 0,
'umls': 0,
'openbookqa': 0,
'commonsenseqa': 0
}
sp = ['qald', 'lc-quad', 'webquestionssp', 'complexwebquestions', 'cfq']
ir = ['simplequestions', 'webquestions', 'complexquestions', 'metaqa']
rl = ['countries', 'wn18rr', 'kinship', 'nell-995', 'fb15k-237', 'umls']
hyb = ['openbookqa', 'commonsenseqa']
pdfs = glob.glob("*.pdf")
n_papers = len(pdfs)
for pdf in tqdm(pdfs):
with pdfplumber.open(rf'{pdf}') as pdf:
n_pages = len(pdf.pages)
text = ''
for page in range(n_pages):
text += pdf.pages[page].extract_text().lower()
for key in counter:
if key in text:
counter[key] += 1
res = {'qald': 44, 'lc-quad': 30, 'webquestionssp': 18, 'complexwebquestions': 13, 'cfq': 2, 'simplequestions': 69, 'openbookqa': 3, 'webquestions': 58, 'complexquestions': 61, 'commonsenseqa': 9, 'metaqa': 16, 'countries': 37, 'wn18rr': 43, 'kinship': 16, 'nell-995': 18, 'fb15k-237': 58, 'umls': 18 }
sps = [(i, res[i]) for i in res if i in sp]
irs = [(i, res[i]) for i in res if i in ir]
rls = [(i, res[i]) for i in res if i in rl]
hybs = [(i, res[i]) for i in res if i in hyb]
n_total = sum(res[i] for i in res)
group_names=[
f'SP ({round((sum(i[1] for i in sps) / n_total * 100), 2)}%)',
f'IR ({round((sum(i[1] for i in irs) / n_total * 100), 2)}%)',
f'RL ({round((sum(i[1] for i in rls) / n_total * 100), 2)}%)',
f'Hybrid ({round((sum(i[1] for i in hybs) / n_total * 100), 2)}%)']
group_size=[
sum(i[1] for i in sps),
sum(i[1] for i in irs),
sum(i[1] for i in rls),
sum(i[1] for i in hybs)
]
subgroup_names= [i[0] for i in sps] + [i[0] for i in irs] + [i[0] for i in rls] + [i[0] for i in hybs]
subgroup_size = [i[1] for i in sps] + [i[1] for i in irs] + [i[1] for i in rls] + [i[1] for i in hybs]
a, b, c, d =[plt.cm.Blues, plt.cm.Reds, plt.cm.Greens, plt.cm.Purples]
fig, ax = plt.subplots()
ax.axis('equal')
mypie, _ = ax.pie(group_size, radius=1.4, labels=group_names, colors=[a(0.6), b(0.6), c(0.6), d(0.6)])
plt.setp(mypie, width=0.2, edgecolor='white')
cols = []
i = 0.5
for _ in range(len(sps)):
cols.append(a(1 - i))
i += 0.1
i = 0.5
for _ in range(len(irs)):
cols.append(b(1 - i))
i += 0.1
i = 0.5
for _ in range(len(rls)):
cols.append(c(1 - i))
i += 0.1
i = 0.7
for _ in range(len(hybs)):
cols.append(d(1 - i))
i += 0.1
mypie2, labels = ax.pie(subgroup_size, radius=1.4-0.2, labels=subgroup_names, labeldistance=0.7, colors=cols)
plt.setp(mypie2, width=0.6, edgecolor='white')
plt.margins(0, 0)
for label in labels:
label.set_horizontalalignment('center')
label.set_fontsize(16)
subgroup_names_legs = []
for c in sps:
subgroup_names_legs.append(f'{c[0]} = {round((c[1] / n_total) * 100, 2)}%')
for c in irs:
subgroup_names_legs.append(f'{c[0]} = {round((c[1] / n_total) * 100, 2)}%')
for c in rls:
subgroup_names_legs.append(f'{c[0]} = {round((c[1] / n_total) * 100, 2)}%')
for c in hybs:
subgroup_names_legs.append(f'{c[0]} = {round((c[1] / n_total) * 100, 2)}%')
plt.legend(subgroup_names_legs,loc='best')
plt.legend(loc=(0.9, 0.1))
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles[3:], subgroup_names_legs, loc=(0.9, 0.1))
plt.show()
mixture = [
'qald', 'cfq', 'metaqa', 'nell-995', 'fb15k-237'
]
mostly_sh = [
'webquestionssp', 'simplequestions', 'countries', 'wn18rr', 'kinship', 'umls'
]
mostly_mh = [
'lc-quad', 'complexwebquestions', 'complexquestions', 'openbookqa', 'commonsenseqa'
]
mixs = sum(res[i] for i in res if i in mixture)
shs = sum(res[i] for i in res if i in mostly_sh)
mhs = sum(res[i] for i in res if i in mostly_mh)
labels = 'Mixture S-H & M-H', 'Mostly S-H', 'Mostly M-H'
sizes = [mixs, shs, mhs]
fig1, ax1 = plt.subplots()
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
temp, t, labels = ax1.pie(sizes, labels=labels, autopct='%1.1f%%', shadow=False, startangle=90)
for label1, label2 in zip(labels, t):
label1.set_horizontalalignment('center')
label1.set_fontsize(18)
# label2.set_horizontalalignment('center')
label2.set_fontsize(14)
plt.show()