-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmain.py
94 lines (65 loc) · 3.95 KB
/
main.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
from subprocess import check_call
import sys
import os
import csv
PYTHON = sys.executable
#################################### set the full file paths ###############################################
i2b2_relations_challenge_directory = "i2b2/relations/"
i2b2_medications_challenge_directory = "i2b2/medication/"
i2b2_heart_disease_risk_challenge_directory = "i2b2/heart-disease-risk/"
i2b2_obesity_challenge_directory = "i2b2/obesity/"
i2b2_smoking_challenge_directory = "i2b2/smoking/"
i2b2_coreference_challeneg_directory = "i2b2/coreference"
templates_directory = "templates/templates-all.csv"
#################################### make output directory if it does not already exist #########################
cwd = os.getcwd()
model_dir = "output/"
if not os.path.exists(os.path.join(cwd,model_dir)):
os.makedirs(model_dir)
output_directory = os.path.join(cwd,model_dir) ## you can modify this to change the output directory path ##
###########################################################################################################
matching_notes = os.path.join("generation/i2b2_relations/", "matching_notes.csv")
match_file = open(matching_notes)
csvreader = csv.reader(match_file)
matching_files = list(csvreader) # relation, coreference
new_file = []
new_file.append(matching_files[0])
flag = 0
for file in matching_files[1:]:
if i2b2_relations_challenge_directory in file[0]:
flag = 1
break
new_file.append([os.path.join(i2b2_relations_challenge_directory,file[0]),os.path.join(i2b2_coreference_challeneg_directory,file[1])])
if flag == 0:
ofile = open(matching_notes, "w")
filewriter = csv.writer(ofile, delimiter="\t")
for val in new_file:
filewriter.writerow(val)
ofile.close()
################################### run the generation scripts #######################################
cmd = "{python} generation/i2b2_medications/medication-answers.py --i2b2_dir={i2b2_dir} --templates_dir={templates_dir} --output_dir={output_dir}".format(python=PYTHON, i2b2_dir=i2b2_medications_challenge_directory, templates_dir=templates_directory, output_dir=output_directory)
print(cmd)
check_call(cmd, shell=True)
cmd = "{python} generation/i2b2_relations/relations-answers.py --i2b2_dir={i2b2_dir} --templates_dir={templates_dir} --output_dir={output_dir}".format(python=PYTHON, i2b2_dir=i2b2_relations_challenge_directory, templates_dir=templates_directory, output_dir=output_directory)
print(cmd)
check_call(cmd, shell=True)
cmd = "{python} generation/i2b2_heart_disease_risk/risk-answers.py --i2b2_dir={i2b2_dir} --templates_dir={templates_dir} --output_dir={output_dir}".format(python=PYTHON, i2b2_dir=i2b2_heart_disease_risk_challenge_directory, templates_dir=templates_directory, output_dir=output_directory)
print(cmd)
check_call(cmd, shell=True)
cmd = "{python} generation/i2b2_smoking/smoking-answers.py --i2b2_dir={i2b2_dir} --templates_dir={templates_dir} --output_dir={output_dir}".format(python=PYTHON, i2b2_dir=i2b2_smoking_challenge_directory, templates_dir=templates_directory, output_dir=output_directory)
print(cmd)
check_call(cmd, shell=True)
cmd = "{python} generation/i2b2_obesity/obesity-answers.py --i2b2_dir={i2b2_dir} --templates_dir={templates_dir} --output_dir={output_dir}".format(python=PYTHON, i2b2_dir=i2b2_obesity_challenge_directory, templates_dir=templates_directory, output_dir=output_directory)
print(cmd)
check_call(cmd, shell=True)
################## combine all the output files and generate the output in normal format ####################
cmd = "{python} generation/combine_data/combine_answers.py --output_dir={output_dir}".format(python=PYTHON, output_dir=output_directory)
print(cmd)
check_call(cmd, shell=True)
##################### convert normal output to squad format ##################################
######################### basic analysis of the dataset #######################################
'''
cmd = "{python} evaluation/analysis.py".format(python=PYTHON)
print(cmd)
check_call(cmd, shell=True)
'''