-
Notifications
You must be signed in to change notification settings - Fork 2
/
pipeline.py
154 lines (119 loc) · 4.56 KB
/
pipeline.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
import os
import shutil
import time
import sys
import configparser
import itertools
from pyreval import splitsent, stanford
from splitsent import split
from Stanford.stanford import *
from Pyramid.pyramid import pyramidmain
basedir = "/home/nlp/pxs288/SU21/PyrEval/PyrEval_0615/"
homedir = basedir+"Datasets"
rawdir = basedir+"Raw"
preprocessdir = basedir+"Preprocess"
pyramiddir = basedir+"Pyramid"
scoredir = basedir+"Scoring"
resultdir = basedir+"Results"
stanforddir = basedir+"Stanford"
def cleanup():
print("Cleaning up previous iteration files")
shutil.rmtree(rawdir)
os.mkdir(rawdir)
# shutil.rmtree(preprocessdir+"/wise_crowd_summaries")
# os.mkdir(preprocessdir+"/wise_crowd_summaries")
# shutil.rmtree(preprocessdir+"/peer_summaries")
# os.mkdir(preprocessdir+"/peer_summaries")
shutil.rmtree(basedir+"/log")
os.mkdir(basedir+"/log")
#shutil.rmtree(resultdir)
#os.mkdir(resultdir)
start = time.time()
counter = 0
for x in sorted(os.listdir(homedir), reverse=True):
print(x)
try:
cleanup()
except:
pass
res = os.path.join(resultdir,x)
if x ==".DS_Store":
continue
if not os.path.isdir(res):
os.mkdir(res)
else:
pass
tempdir = os.path.join(homedir, x)
print("Working on dataset "+ x)
for each in os.listdir(tempdir):
# if os.path.isdir(tempdir+"/"+each):
# continue
shutil.copytree(os.path.join(tempdir,each), os.path.join(rawdir,each))
if not os.path.exists(os.path.join(rawdir,each,'split'):
os.mkdir(os.path.join(rawdir,each,'split')
split(os.path.join(rawdir,'model'), os.path.join(rawdir,'model','split'))
split(os.path.join(rawdir,'peers'), os.path.join(rawdir,'model','peers'))
# splitsent('')
# stanford('')
print("Stanford")
os.chdir(stanforddir)
stanfordmain(os.path.join(rawdir,'model','split'), 1, basedir)
os.chdir(stanforddir)
stanfordmain(os.path.join(rawdir,'model','peers'), 2, basedir)
# sys.exit()
print("Preprocessing")
os.chdir(preprocessdir)
os.system("python preprocess.py 1")
os.system("python preprocess.py 2")
os.chdir(basedir)
parser = configparser.ConfigParser()
parser.read('parameters.ini')
parser.set('Paths', 'OutputPyramidName', x)
if not os.path.exists(os.path.join(scoredir, 'scu')):
os.makedirs(os.path.join(scoredir, 'scu'))
if not os.path.exists(os.path.join(scoredir, 'sizes')):
os.makedirs(os.path.join(scoredir, 'sizes'))
if not os.path.exists(os.path.join(scoredir, 'pyrs', 'pyramids')):
os.makedirs(os.path.join(scoredir, 'pyrs', 'pyramids'))
if not os.path.exists(os.path.join(scoredir,'temp')):
os.makedirs(os.path.join(scoredir, 'temp'))
if not os.path.exists(os.path.join(scoredir,'temp')):
os.makedirs(os.path.join(scoredir, 'temp'))
with open('parameters.ini', 'w') as f:
parser.write(f)
os.chdir(pyramiddir)
# if 'av' not in x:
pyramidmain(x)
topk = ['2', '4', '8']
sorting = ['product', 'stddev', 'cosine', 'normsum']
weighting = ['product', 'stddev', 'cosine', 'normsum']
scheme = ["sum", "max", "average"]
comb = itertools.product(topk, sorting, weighting, scheme)
for config in comb:
conf_str = '_'.join(config)
os.chdir(basedir)
parser = configparser.ConfigParser()
parser.read('parameters.ini')
parser.set('Scoring_Params', 'TopKScus', config[0])
parser.set('Scoring_Params', 'SortingMetric', config[1])
parser.set('Scoring_Params', 'WeightingMetric', config[2])
parser.set('Scoring_Params', 'WeightScheme', config[3])
with open('parameters.ini', 'w+') as f:
parser.write(f)
os.chdir(scoredir)
os.system("python scoring.py -t -l -a")
os.chdir(res)
os.mkdir(conf_str)
shutil.copytree(os.path.join(basedir,"log"), os.path.join(res, conf_str,"log"))
shutil.move(os.path.join(scoredir,"results.csv"), os.path.join(res,conf_str))
counter += 1
os.chdir(scoredir)
for each in os.listdir("sizes"):
shutil.move(os.path.join("sizes", each), res)
for each in os.listdir("scu"):
shutil.move(os.path.join("scu", each), res)
for each in os.listdir(os.path.join("pyrs","pyramids")):
shutil.move(os.path.join("pyrs","pyramids",each), res)
os.chdir(homedir)
end = time.time()
print(str(counter)+" configurations processed. Time elapsed = "+ str(end-start))