-
Notifications
You must be signed in to change notification settings - Fork 0
/
io_helper.py
173 lines (148 loc) · 5.47 KB
/
io_helper.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# read_input.py
import sys
import mpi
def write_master(msg, handle=sys.stderr):
if mpi.rank == 0:
msg = "[%d] %s" %(mpi.rank, msg)
handle.write(msg)
handle.flush()
def write_all(msg, handle=sys.stderr):
'''Have all processes write msg to sys.stderr; Prepend rank id to the message.'''
msg = "[%d] %s" %(mpi.rank, msg)
handle.write(msg)
def open_files(FLAGS):
''' Helper function to read_input()
Try to open files read from arguments for reading '''
file_handles = { }
if FLAGS.inverse_dev is not None:
try:
file_handles['inverse_dev'] = open(FLAGS.inverse_dev, 'r')
except:
write_master("Could not open output file %s for writing\n" %(FLAGS.inverse_dev))
sys.exit(3)
if FLAGS.inverse is not None:
try:
file_handles['inverse'] = open(FLAGS.inverse, 'r')
except:
write_master("Could not open output file %s for writing\n" %(FLAGS.inverse))
sys.exit(3)
if FLAGS.out is not None:
try:
file_handles['out'] = open(FLAGS.out, 'w')
except:
write_master("Could not open output file %s for writing\n" %(FLAGS.out))
sys.exit(3)
else:
file_handles['out'] = sys.stdout
if FLAGS.a1 is not None:
try:
file_handles['a1'] = open(FLAGS.a1, 'r')
except:
write_master("Could not open m4-intersection file %s for reading\n" %(FLAGS.a1))
sys.exit(3)
if FLAGS.a1_dev is not None:
try:
file_handles['a1_dev'] = open(FLAGS.a1_dev, 'r')
except:
write_master("Could not open m4-intersection-dev file %s for reading\n" %(FLAGS.a1_dev))
sys.exit(3)
if FLAGS.a2 is not None:
try:
file_handles['a2'] = open(FLAGS.a2, 'r')
except:
write_master("Could not open a2 file %s for reading\n" %(FLAGS.a2))
sys.exit(3)
if FLAGS.a2_dev is not None:
try:
file_handles['a2_dev'] = open(FLAGS.a2_dev, 'r')
except:
write_master("Could not open a2_dev file %s for reading\n" %(FLAGS.a2_dev))
sys.exit(3)
if FLAGS.ftrees is not None:
try:
file_handles['ftrees'] = open(FLAGS.ftrees, 'r')
except:
write_master("Could not open ftrees file %s for reading\n" %(FLAGS.ftrees))
sys.exit(3)
try:
file_handles['f'] = open(FLAGS.f, 'r')
except:
write_master("Could not open ftrain file %s for reading\n" % FLAGS.f)
sys.exit(3)
try:
file_handles['e'] = open(FLAGS.e, 'r')
except:
write_master("Could not open etrain file %s for reading\n" % FLAGS.e)
sys.exit(3)
try:
file_handles['etrees'] = open(FLAGS.etrees, 'r')
except:
write_master("Could not open etrees train file %s for reading\n" % FLAGS.etrees)
sys.exit(3)
if FLAGS.gold is not None:
try:
file_handles['gold'] = open(FLAGS.gold, 'r')
except:
write_master("Could not open gold train file %s for reading\n" % FLAGS.gold)
sys.exit(3)
if FLAGS.weights is not None:
try:
file_handles['weights'] = open(FLAGS.weights, 'r')
except:
write_master("Could not open weights file %s for reading\n" % FLAGS.weights)
sys.exit(3)
if FLAGS.evcb is not None:
try:
file_handles['evcb'] = open(FLAGS.evcb, 'r')
except:
write_master("Could not open evcb file %s for reading\n" % FLAGS.evcb)
sys.exit(3)
if FLAGS.fvcb is not None:
try:
file_handles['fvcb'] = open(FLAGS.fvcb, 'r')
except:
write_master("Could not open fvcb file %s for reading\n" % FLAGS.fvcb)
sys.exit(3)
if FLAGS.fdev is not None:
try:
file_handles['fdev'] = open(FLAGS.fdev, 'r')
except:
sys.stderr.write("Could not open fdev file %s for reading\n" % FLAGS.fdev)
sys.exit(3)
if FLAGS.edev is not None:
try:
file_handles['edev'] = open(FLAGS.edev, 'r')
except:
sys.stderr.write("Could not open edev file %s for reading\n" % FLAGS.edev)
sys.exit(3)
if FLAGS.etreesdev is not None:
try:
file_handles['etreesdev'] = open(FLAGS.etreesdev, 'r')
except:
sys.stderr.write("Could not open etrees dev file %s for reading\n" % FLAGS.etreesdev)
sys.exit(3)
if FLAGS.pef is not None:
try:
file_handles['pef'] = open(FLAGS.pef, 'r')
except:
sys.stderr.write("Could not open pef file %s for reading\n" % FLAGS.pef)
sys.exit(3)
if FLAGS.pfe is not None:
try:
file_handles['pfe'] = open(FLAGS.pfe, 'r')
except:
sys.stderr.write("Could not open pfe file %s for reading\n" % FLAGS.pfe)
sys.exit(3)
if FLAGS.ftreesdev is not None:
try:
file_handles['ftreesdev'] = open(FLAGS.ftreesdev, 'r')
except:
sys.stderr.write("Could not open ftrees dev file %s for reading\n" % FLAGS.ftreesdev)
sys.exit(3)
if FLAGS.golddev is not None:
try:
file_handles['golddev'] = open(FLAGS.golddev, 'r')
except:
sys.stderr.write("Could not open gold dev file %s for reading\n" % FLAGS.golddev)
sys.exit(3)
return file_handles