Datasets:
siyue
commited on
Commit
·
f1bb559
1
Parent(s):
7d85704
dict
Browse files
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 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
}
|
234 |
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
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":
|