/
javad_ILPinput.py
99 lines (82 loc) · 2.45 KB
/
javad_ILPinput.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
import sys
import makesets
import pickle
from random import randint
import EntityFileCreator as EF
OUT=None
def cleannum(n):
return ''.join([x for x in n if x.isdigit() or x=='.' or x=='x' or x=='x*'])
def make_eq(q,a,e,VERBOSE,TRAIN):
bigtexamples = {x:([],[]) for x in ["+","*",'/','-','=']}
#wps = open(q).readlines()
#answs = open(a).readlines()
#VERBOSE=True
wps = q
for k in range(len(wps)):
if VERBOSE:
for i in range(len(wps)):
print(i,wps[i])
k = int(input())
print(k)
problem = wps[k]
#First preprocessing, tokenize slightly
problem = problem.strip().split(" ")
for i,x in enumerate(problem):
if len(x)==0:continue
if x[-1] in [',','.','?']:
problem[i] = x[:-1]+" "+x[-1]
problem = ' '.join(problem)
problem = " " + problem + " "
print(problem)
story = read_parse(k)
sets = makesets.makesets(story['sentences'])
if e[k].strip() != '':
irrelev = e[k].strip().split(" ")
imap = [(x[-1],x) for x in irrelev]
if not all([x[0] for x in imap])=='0':
print(imap)
for x in [x for x in imap if x[0] == '0']:
ent,num,v = x[1].split(',')
if ent in ["$","dollar"]: continue
else:
sets = [x for x in sets if x[1].num != num]
pickle.dump(sets, open('madesets/'+str(k)+'.pickle','wb'))
EF.main(sets,k,a[k],sys.argv[1])
sets = [x for x in sets if makesets.floatcheck(x[1].num) or x[1].num == 'x']
print(sets)
for z in sets:
z[1].details()
def read_parse(k):
return pickle.load(open('s_data/'+str(k)+'.pickle', 'rb'))
def parse_inp(inp):
q=[]
a=[]
e=[]
with open(inp) as f:
f = f.readlines()
i=0
while i<len(f):
q.append(f[i])
i+=1
e.append(f[i])
i+=1
a.append(f[i])
i+=1
return (q,a,e)
if __name__=="__main__":
#q, a = sys.argv[1:3]
inp = sys.argv[1]
q,a,e = parse_inp(inp)
VERBOSE=False
TRAIN=False
'''
if len(sys.argv)>3:
if sys.argv[3]=='v':
VERBOSE=True
elif sys.argv[3]=='t':
TRAIN = True
OUT = sys.argv[4]
'''
# q = q[-10:]
# a = a[-10:]
make_eq(q,a,e,VERBOSE,TRAIN)