Datasets:
siyue
commited on
Commit
·
e093a86
1
Parent(s):
d2912aa
parse
Browse files
squall.py
CHANGED
@@ -18,7 +18,7 @@
|
|
18 |
|
19 |
|
20 |
import json
|
21 |
-
|
22 |
import datasets
|
23 |
from datasets.tasks import QuestionAnsweringExtractive
|
24 |
|
@@ -152,6 +152,83 @@ class Squall(datasets.GeneratorBasedBuilder):
|
|
152 |
if split_key != 'test':
|
153 |
with open(squall_full, encoding="utf-8") as f:
|
154 |
squall_full_data = json.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
with open(dev_ids) as f:
|
156 |
dev_ids = json.load(f)
|
157 |
if split_key == "train":
|
|
|
18 |
|
19 |
|
20 |
import json
|
21 |
+
import re
|
22 |
import datasets
|
23 |
from datasets.tasks import QuestionAnsweringExtractive
|
24 |
|
|
|
152 |
if split_key != 'test':
|
153 |
with open(squall_full, encoding="utf-8") as f:
|
154 |
squall_full_data = json.load(f)
|
155 |
+
|
156 |
+
NUM_MAPPING = {
|
157 |
+
'half': 0.5,
|
158 |
+
'one': 1,
|
159 |
+
'two': 2,
|
160 |
+
'three': 3,
|
161 |
+
'four': 4,
|
162 |
+
'five': 5,
|
163 |
+
'six': 6,
|
164 |
+
'seven': 7,
|
165 |
+
'eight': 8,
|
166 |
+
'nine': 9,
|
167 |
+
'ten': 10,
|
168 |
+
'eleven': 11,
|
169 |
+
'twelve': 12,
|
170 |
+
'twenty': 20,
|
171 |
+
'thirty': 30,
|
172 |
+
'once': 1,
|
173 |
+
'twice': 2,
|
174 |
+
'first': 1,
|
175 |
+
'second': 2,
|
176 |
+
'third': 3,
|
177 |
+
'fourth': 4,
|
178 |
+
'fifth': 5,
|
179 |
+
'sixth': 6,
|
180 |
+
'seventh': 7,
|
181 |
+
'eighth': 8,
|
182 |
+
'ninth': 9,
|
183 |
+
'tenth': 10,
|
184 |
+
'hundred': 100,
|
185 |
+
'thousand': 1000,
|
186 |
+
'million': 1000000,
|
187 |
+
'jan': 1,
|
188 |
+
'feb': 2,
|
189 |
+
'mar': 3,
|
190 |
+
'apr': 4,
|
191 |
+
'may': 5,
|
192 |
+
'jun': 6,
|
193 |
+
'jul': 7,
|
194 |
+
'aug': 8,
|
195 |
+
'sep': 9,
|
196 |
+
'oct': 10,
|
197 |
+
'nov': 11,
|
198 |
+
'dec': 12,
|
199 |
+
'january': 1,
|
200 |
+
'february': 2,
|
201 |
+
'march': 3,
|
202 |
+
'april': 4,
|
203 |
+
'june': 6,
|
204 |
+
'july': 7,
|
205 |
+
'august': 8,
|
206 |
+
'september': 9,
|
207 |
+
'october': 10,
|
208 |
+
'november': 11,
|
209 |
+
'december': 12,
|
210 |
+
}
|
211 |
+
|
212 |
+
def parse_number(s):
|
213 |
+
if s in NUM_MAPPING:
|
214 |
+
return NUM_MAPPING[s]
|
215 |
+
s = s.replace(',', '')
|
216 |
+
# https://stackoverflow.com/questions/4289331/python-extract-numbers-from-a-string
|
217 |
+
ret = re.findall(r"[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?", s)
|
218 |
+
if len(ret) > 0:
|
219 |
+
return ret[0]
|
220 |
+
return None
|
221 |
+
|
222 |
+
for instance in squall_full_data:
|
223 |
+
has_number = False
|
224 |
+
numbers = []
|
225 |
+
for x in instance["nl"]:
|
226 |
+
numbers.append(parse_number(x))
|
227 |
+
if numbers[-1] is not None:
|
228 |
+
has_number = True
|
229 |
+
instance["numbers"] = numbers
|
230 |
+
instance["has_number"] = has_number
|
231 |
+
|
232 |
with open(dev_ids) as f:
|
233 |
dev_ids = json.load(f)
|
234 |
if split_key == "train":
|