Datasets:
siyue
commited on
Commit
•
b5cba51
1
Parent(s):
d65105b
add
Browse files
squall.py
CHANGED
@@ -155,7 +155,18 @@ class Squall(datasets.GeneratorBasedBuilder):
|
|
155 |
squall_full = filepath["squall"]
|
156 |
dev_ids = filepath["dev-" + self.config.name]
|
157 |
test = filepath["wtq-test"]
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
if split_key != 'test':
|
160 |
with open(squall_full, encoding="utf-8") as f:
|
161 |
squall_full_data = json.load(f)
|
@@ -236,16 +247,6 @@ class Squall(datasets.GeneratorBasedBuilder):
|
|
236 |
instance["numbers"] = numbers
|
237 |
instance["has_number"] = has_number
|
238 |
|
239 |
-
def transform(sample, sample_key, keys):
|
240 |
-
cols = {}
|
241 |
-
n_col = len(sample[sample_key])
|
242 |
-
for k in range(len(keys)):
|
243 |
-
tmp = []
|
244 |
-
for j in range(n_col):
|
245 |
-
tmp.append(sample[sample_key][j][k])
|
246 |
-
cols[keys[k]] = tmp
|
247 |
-
return cols
|
248 |
-
|
249 |
with open(dev_ids) as f:
|
250 |
dev_ids = json.load(f)
|
251 |
if split_key == "train":
|
@@ -254,7 +255,6 @@ class Squall(datasets.GeneratorBasedBuilder):
|
|
254 |
set = [x for x in squall_full_data if x["tbl"] in dev_ids]
|
255 |
idx = 0
|
256 |
for sample in set:
|
257 |
-
|
258 |
# transform columns
|
259 |
keys = ["raw_header", "tokenized_header", "column_suffixes", "column_dtype", "example"]
|
260 |
cols = transform(sample, "columns", keys)
|
@@ -267,7 +267,6 @@ class Squall(datasets.GeneratorBasedBuilder):
|
|
267 |
# transform ralign
|
268 |
keys = ["aligned_sql_token_type", "aligned_sql_token_info"]
|
269 |
raligns = transform(sample, "nl_ralign", keys)
|
270 |
-
|
271 |
yield idx, {
|
272 |
"nt": sample["nt"],
|
273 |
"tbl": sample["tbl"],
|
@@ -289,11 +288,9 @@ class Squall(datasets.GeneratorBasedBuilder):
|
|
289 |
test_data = json.load(f)
|
290 |
idx = 0
|
291 |
for sample in test_data:
|
292 |
-
|
293 |
# transform columns
|
294 |
keys = ["raw_header", "tokenized_header", "column_suffixes", "column_dtype", "example"]
|
295 |
cols = transform(sample, "columns", keys)
|
296 |
-
|
297 |
yield idx, {
|
298 |
"nt": sample["nt"],
|
299 |
"tbl": sample["tbl"],
|
|
|
155 |
squall_full = filepath["squall"]
|
156 |
dev_ids = filepath["dev-" + self.config.name]
|
157 |
test = filepath["wtq-test"]
|
158 |
+
|
159 |
+
# transform the original squall data structure (list of things) to dict
|
160 |
+
def transform(sample, sample_key, keys):
|
161 |
+
cols = {}
|
162 |
+
n_col = len(sample[sample_key])
|
163 |
+
for k in range(len(keys)):
|
164 |
+
tmp = []
|
165 |
+
for j in range(n_col):
|
166 |
+
tmp.append(sample[sample_key][j][k])
|
167 |
+
cols[keys[k]] = tmp
|
168 |
+
return cols
|
169 |
+
|
170 |
if split_key != 'test':
|
171 |
with open(squall_full, encoding="utf-8") as f:
|
172 |
squall_full_data = json.load(f)
|
|
|
247 |
instance["numbers"] = numbers
|
248 |
instance["has_number"] = has_number
|
249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
with open(dev_ids) as f:
|
251 |
dev_ids = json.load(f)
|
252 |
if split_key == "train":
|
|
|
255 |
set = [x for x in squall_full_data if x["tbl"] in dev_ids]
|
256 |
idx = 0
|
257 |
for sample in set:
|
|
|
258 |
# transform columns
|
259 |
keys = ["raw_header", "tokenized_header", "column_suffixes", "column_dtype", "example"]
|
260 |
cols = transform(sample, "columns", keys)
|
|
|
267 |
# transform ralign
|
268 |
keys = ["aligned_sql_token_type", "aligned_sql_token_info"]
|
269 |
raligns = transform(sample, "nl_ralign", keys)
|
|
|
270 |
yield idx, {
|
271 |
"nt": sample["nt"],
|
272 |
"tbl": sample["tbl"],
|
|
|
288 |
test_data = json.load(f)
|
289 |
idx = 0
|
290 |
for sample in test_data:
|
|
|
291 |
# transform columns
|
292 |
keys = ["raw_header", "tokenized_header", "column_suffixes", "column_dtype", "example"]
|
293 |
cols = transform(sample, "columns", keys)
|
|
|
294 |
yield idx, {
|
295 |
"nt": sample["nt"],
|
296 |
"tbl": sample["tbl"],
|