-
Notifications
You must be signed in to change notification settings - Fork 32
/
rouge_results_writer.py
62 lines (47 loc) · 2.44 KB
/
rouge_results_writer.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
import os
import os.path
import csv
RESULTS_DIRECTORY_FORMAT = 'results_{dataset}'
def export_results(dataset, results, method):
successes = float(results.successes)
print "Successful tests: " + str(results.successes)
print "Failed tests: " + str(results.errors)
print "Timed out tests: " + str(results.timeouts)
if successes == 0:
return
results_directory = RESULTS_DIRECTORY_FORMAT.format(dataset=dataset)
if not os.path.exists(results_directory):
os.makedirs(results_directory)
method_name = " ({method})".format(method=method)
avg_rouge1_fscore = results.output['rouge_1_f_score']
print "Average F-score for ROUGE-1 metric: " + str(avg_rouge1_fscore)
avg_rouge2_fscore = results.output['rouge_2_f_score']
print "Average F-score for ROUGE-2 metric: " + str(avg_rouge2_fscore)
avg_su4_fscore = results.output['rouge_su4_f_score']
print "Average F-score for ROUGE-SU4 metric: " + str(avg_su4_fscore)
# Export ROUGE measures on successes.
with open(os.path.join(results_directory, 'avg_rouge1_fscore.csv'), 'w') as csvfile:
csv_writer = csv.writer(csvfile)
csv_writer.writerow(['AVG ROUGE-1 F-measure' + method_name])
csv_writer.writerow([str(avg_rouge1_fscore)])
with open(os.path.join(results_directory, 'avg_rouge2_fscore.csv'), 'w') as csvfile:
csv_writer = csv.writer(csvfile)
csv_writer.writerow(['AVG ROUGE-2 F-measure' + method_name])
csv_writer.writerow([str(avg_rouge2_fscore)])
with open(os.path.join(results_directory, 'avg_rougesu4_fscore.csv'), 'w') as csvfile:
csv_writer = csv.writer(csvfile)
csv_writer.writerow(['AVG ROUGE-SU4 F-measure' + method_name])
csv_writer.writerow([str(avg_su4_fscore)])
# Exports overall results.
with open(os.path.join(results_directory, 'textrank_successes.csv'), 'w') as csvfile:
csv_writer = csv.writer(csvfile)
csv_writer.writerow(['Successes'])
csv_writer.writerow([str(results.successes)])
with open(os.path.join(results_directory, 'textrank_failures.csv'), 'w') as csvfile:
csv_writer = csv.writer(csvfile)
csv_writer.writerow(['Failures'])
csv_writer.writerow([str(results.errors)])
with open(os.path.join(results_directory, 'textrank_timeouts.csv'), 'w') as csvfile:
csv_writer = csv.writer(csvfile)
csv_writer.writerow(['Timeouts'])
csv_writer.writerow([str(results.timeouts)])