-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
255 lines (202 loc) · 6.9 KB
/
run.py
File metadata and controls
255 lines (202 loc) · 6.9 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
from summa.summarizer import summarize
from data import Summaries
import logging
from rouge import Rouge
from nltk.tokenize import sent_tokenize
import spacy
import re
import pandas as pd
import pytextrank
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-colorblind')
import pandas as pd
import csv
import json
# nlp = spacy.load('en_core_web_sm')
logging.basicConfig(level=logging.INFO)
def print_scores(scores):
toprint = ""
for key in scores.keys():
toprint += " & " + str(round(scores[key]['f']*100,2))
print(toprint)
def unique_ngrams():
duc = [0.12156329, 0.45697504, 0.64084184, 0.73831058]
legal = [0.41459283, 0.78600083, 0.88397464, 0.92316188]
ind = np.arange(4)
width = .34
fig1, ax1 = plt.subplots()
ax1.set_title('Unique n-grams')
plt.ylabel('% that are unique')
plt.bar(ind, duc, width, label="DUC2002")
plt.bar(ind + width + .02, legal, width, label="Ours")
plt.xticks(ind + width/2 + 0.01, ('1-grams', '2-grams', '3-grams', '4-grams'))
plt.legend(loc='best')
fig1.set_size_inches(5, 3.5)
fig1.show()
def save_legaltldr():
df = pd.read_csv("data/tldrlegal_v1.csv")
df.set_index('uid', inplace=True)
export = df.to_json(r'tldrlegal_v1.json', orient='index')
pass
def save_tosdr():
reader = csv.DictReader(open("data/tosdr_annotated.csv"))
data = {}
for row in reader:
if row['tldr_code'].startswith("1") \
or row['title_code'].startswith("1") \
or row['case_code'].startswith("1"):
data[row['uid']] = {}
data[row['uid']]['note'] = row['note']
data[row['uid']]['name'] = row['quoteDoc']
data[row['uid']]['text'] = row['text']
data[row['uid']]['urls'] = row['urls']
summ = False
onethrow = False
twothrow = False
if row['tldr_code'].startswith("1") \
or row['tldr_code'].startswith("2") \
or row['tldr_code'].startswith("3"):
data[row['uid']]['tldr_text'] = row['tldr']
data[row['uid']]['tldr_code'] = row['tldr_code']
if row['tldr_code'].startswith("1"):
if len(row['tldr']) > len(row['text']):
onethrow = True
else:
data[row['uid']]['summary'] = row['tldr']
summ = True
if row['case_code'].startswith("1") \
or row['case_code'].startswith("2") \
or row['case_code'].startswith("3"):
data[row['uid']]['case_text'] = row['case']
data[row['uid']]['case_code'] = row['case_code']
if not summ:
if row['case_code'].startswith("1"):
if len(row['case']) > len(row['text']):
onethrow = True
else:
data[row['uid']]['summary'] = row['case']
summ = True
# if onethrow:
# if row['case_code'].startswith("2"):
# if len(row['case']) > len(row['text']):
# twothrow = True
# else:
# data[row['uid']]['summary'] = row['case']
# summ = True
if row['title_code'].startswith("1") \
or row['title_code'].startswith("2") \
or row['title_code'].startswith("3"):
data[row['uid']]['title_text'] = row['title']
data[row['uid']]['title_code'] = row['title_code']
if row['title_code'].startswith("1"):
if len(row['title']) > len(row['text']):
onethrow = True
else:
data[row['uid']]['summary'] = row['title']
summ = True
# elif onethrow:
# if row['title_code'].startswith("2"):
# if len(row['title']) > len(row['text']):
# twothrow = True
# else:
# data[row['uid']]['summary'] = row['title']
# summ = True
# elif twothrow:
# if row['title_code'].startswith("3"):
# if len(row['title']) > len(row['text']):
# data[row['uid']]['summary'] = row['title']
# summ = True
# if not summ:
# print(f"throw {row['uid']}")
# data.pop(row['uid'])
json.dump(data, open("tosdr_v1.json", "w"))
pass
if __name__ == '__main__':
data2 = Summaries(['tosdr_annotated'])
save_tosdr()
# unique_ngrams()
#
# data1 = Summaries(['tldrlegal'])
# print("\n TLDRLegal")
# print("TextRank")
# print_scores(data.textrank())
#
# print("KLSumm")
# print_scores(data.greedy_kl())
#
# print("LEAD1")
# print_scores(data.firstsent())
#
# print("Leadk")
# print_scores(data.firstk())
#
# print("RandomK")
# print_scores(data.randomk())
# print("Readability")
# data.readibility_score()
# # data.log_odds_ratio()
# print("Metrics")
# data.get_metrics()
#
# data2 = Summaries(['tosdr_annotated'])
# print("\n TOSDR Annotated")
# print("TextRank")
# print_scores(data.textrank())
#
# print("KLSumm")
# print_scores(data.greedy_kl())
#
# print("LEAD1")
# print_scores(data.firstsent())
#
# print("Leadk")
# print_scores(data.firstk())
#
# print("RandomK")
# print_scores(data.randomk())
# print("Readability")
# data.readibility_score()
# data.log_odds_ratio()
# print("Metrics")
# data.get_metrics()
# data = Summaries(['tldrlegal','tosdr_annotated'])
# print("\n TLDRLegal and TOSDR")
# print("TextRank")
# print_scores(data.textrank())
#
# print("KLSumm")
# print_scores(data.greedy_kl())
#
# print("LEAD1")
# print_scores(data.firstsent())
#
# print("Leadk")
# print_scores(data.firstk())
# print("RandomK")
# print_scores(data.randomk())
# print("Readability")
# data.readibility_score()
# print("Metrics")
# data.get_metrics()
# data.log_odds_ratio()
# data = Summaries(['DUC2002'])
# print("\n DUC2002")
# print("TextRank")
# print_scores(data.textrank())
#
# print("KLSumm")
# print_scores(data.greedy_kl())
#
# print("LEAD1")
# print_scores(data.firstsent())
#
# print("Leadk")
# print_scores(data.firstk())
# print("RandomK")
# print_scores(data.randomk())
# print("Readability")
# data.readibility_score()
#
# print("Metrics")
# data.get_metrics()