siyue commited on
Commit
f1bb559
1 Parent(s): 7d85704
Files changed (1) hide show
  1. squall.py +79 -77
squall.py CHANGED
@@ -172,86 +172,88 @@ class Squall(datasets.GeneratorBasedBuilder):
172
  align_keys = ["nl_indices", "sql_indices"]
173
  ralign_keys = ["aligned_sql_token_type", "aligned_sql_token_info"]
174
 
175
- if split_key != 'test':
176
- with open(squall_full, encoding="utf-8") as f:
177
- squall_full_data = json.load(f)
178
-
179
- NUM_MAPPING = {
180
- 'half': 0.5,
181
- 'one': 1,
182
- 'two': 2,
183
- 'three': 3,
184
- 'four': 4,
185
- 'five': 5,
186
- 'six': 6,
187
- 'seven': 7,
188
- 'eight': 8,
189
- 'nine': 9,
190
- 'ten': 10,
191
- 'eleven': 11,
192
- 'twelve': 12,
193
- 'twenty': 20,
194
- 'thirty': 30,
195
- 'once': 1,
196
- 'twice': 2,
197
- 'first': 1,
198
- 'second': 2,
199
- 'third': 3,
200
- 'fourth': 4,
201
- 'fifth': 5,
202
- 'sixth': 6,
203
- 'seventh': 7,
204
- 'eighth': 8,
205
- 'ninth': 9,
206
- 'tenth': 10,
207
- 'hundred': 100,
208
- 'thousand': 1000,
209
- 'million': 1000000,
210
- 'jan': 1,
211
- 'feb': 2,
212
- 'mar': 3,
213
- 'apr': 4,
214
- 'may': 5,
215
- 'jun': 6,
216
- 'jul': 7,
217
- 'aug': 8,
218
- 'sep': 9,
219
- 'oct': 10,
220
- 'nov': 11,
221
- 'dec': 12,
222
- 'january': 1,
223
- 'february': 2,
224
- 'march': 3,
225
- 'april': 4,
226
- 'june': 6,
227
- 'july': 7,
228
- 'august': 8,
229
- 'september': 9,
230
- 'october': 10,
231
- 'november': 11,
232
- 'december': 12,
233
- }
234
 
235
- def parse_number(s):
236
- if s in NUM_MAPPING:
237
- return NUM_MAPPING[s]
238
- s = s.replace(',', '')
239
- # https://stackoverflow.com/questions/4289331/python-extract-numbers-from-a-string
240
- ret = re.findall(r"[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?", s)
241
- if len(ret) > 0:
242
- return ret[0]
243
- return None
244
 
245
- for instance in squall_full_data:
246
- has_number = False
247
- numbers = []
248
- for x in instance["nl"]:
249
- numbers.append(parse_number(x))
250
- if numbers[-1] is not None:
251
- has_number = True
252
- instance["numbers"] = numbers
253
- instance["has_number"] = has_number
254
 
 
 
 
255
  with open(dev_ids) as f:
256
  dev_ids = json.load(f)
257
  if split_key == "train":
 
172
  align_keys = ["nl_indices", "sql_indices"]
173
  ralign_keys = ["aligned_sql_token_type", "aligned_sql_token_info"]
174
 
175
+ with open(squall_full, encoding="utf-8") as f:
176
+ squall_full_data = json.load(f)
177
+
178
+ NUM_MAPPING = {
179
+ 'half': 0.5,
180
+ 'one': 1,
181
+ 'two': 2,
182
+ 'three': 3,
183
+ 'four': 4,
184
+ 'five': 5,
185
+ 'six': 6,
186
+ 'seven': 7,
187
+ 'eight': 8,
188
+ 'nine': 9,
189
+ 'ten': 10,
190
+ 'eleven': 11,
191
+ 'twelve': 12,
192
+ 'twenty': 20,
193
+ 'thirty': 30,
194
+ 'once': 1,
195
+ 'twice': 2,
196
+ 'first': 1,
197
+ 'second': 2,
198
+ 'third': 3,
199
+ 'fourth': 4,
200
+ 'fifth': 5,
201
+ 'sixth': 6,
202
+ 'seventh': 7,
203
+ 'eighth': 8,
204
+ 'ninth': 9,
205
+ 'tenth': 10,
206
+ 'hundred': 100,
207
+ 'thousand': 1000,
208
+ 'million': 1000000,
209
+ 'jan': 1,
210
+ 'feb': 2,
211
+ 'mar': 3,
212
+ 'apr': 4,
213
+ 'may': 5,
214
+ 'jun': 6,
215
+ 'jul': 7,
216
+ 'aug': 8,
217
+ 'sep': 9,
218
+ 'oct': 10,
219
+ 'nov': 11,
220
+ 'dec': 12,
221
+ 'january': 1,
222
+ 'february': 2,
223
+ 'march': 3,
224
+ 'april': 4,
225
+ 'june': 6,
226
+ 'july': 7,
227
+ 'august': 8,
228
+ 'september': 9,
229
+ 'october': 10,
230
+ 'november': 11,
231
+ 'december': 12,
232
+ }
 
233
 
234
+ def parse_number(s):
235
+ if s in NUM_MAPPING:
236
+ return NUM_MAPPING[s]
237
+ s = s.replace(',', '')
238
+ # https://stackoverflow.com/questions/4289331/python-extract-numbers-from-a-string
239
+ ret = re.findall(r"[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?", s)
240
+ if len(ret) > 0:
241
+ return ret[0]
242
+ return None
243
 
244
+ for instance in squall_full_data:
245
+ has_number = False
246
+ numbers = []
247
+ for x in instance["nl"]:
248
+ numbers.append(parse_number(x))
249
+ if numbers[-1] is not None:
250
+ has_number = True
251
+ instance["numbers"] = numbers
252
+ instance["has_number"] = has_number
253
 
254
+ self.full_nt_list = [s["nt"] for s in squall_full_data]
255
+
256
+ if split_key != 'test':
257
  with open(dev_ids) as f:
258
  dev_ids = json.load(f)
259
  if split_key == "train":