-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseSdata.py
135 lines (106 loc) · 3.51 KB
/
parseSdata.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
import signal
import sys
import json
import jsonrpclib
import makesets
import pickle
from random import randint
from ILPformat import parse_json
OUT=None
class StanfordNLP:
def __init__(self, port_number=8080):
self.server = jsonrpclib.Server("http://localhost:%d" % port_number)
def parse(self, text):
return json.loads(self.server.parse(text))
nlp = StanfordNLP()
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,VERBOSE,TRAIN):
bigtexamples = {x:([],[]) for x in ["+","*",'/','-','=']}
wps = q #q is the questions
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]
#print problem
#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 + " "
#Percentage Putting
Res = problem
problem=""
for i in range(len(Res)):
if Res[i]=='%':
problem += " percent"
else:
problem += Res[i]
##Change Percentage to times
problem = problem.strip().split(" ")
for i in range(len(problem)-1):
if (problem[i+1]=='percent') or (problem[i+1]=='Percent'):#or (problem[i+1]=='percentage') or (problem[i+1]=='Percentage')
strval = problem[i]
val=''
if strval[0]=='$':
val=strval[1:]
val=float(val)/100.0
problem[i]=str(val)
elif strval[0] in ['0','1','2','3','4','5','6','7','8','9']:
val=strval
val=float(val)/100.0
problem[i]=str(val)
problem[i+1]='times'
problem = ' '.join(problem)
problem = " " + problem + " "
print(problem)
story = nlp.parse(problem)
#print story['sentences']
'''
Gets the That returns a dictionary containing the keys sentences and coref. The key sentences contains a list of dictionaries for each sentence, which
contain parsetree, text, tuples containing the dependencies, and words, containing information about parts of speech, recognized named-entities, etc:
'''
#print story
pickle.dump(story,open("s_data/"+str(k)+".pickle",'wb'))
continue
'''
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] # Takes the problemSet name
#q,a,e = parse_inp(inp)
q,a = parse_json(inp) #A method imported from ILPformat.py and makes question -> q and solution -> a
#print q
#print a
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]
'''
make_eq(q,a,VERBOSE,TRAIN)