Refactor yield per config
Browse files
alt.py
CHANGED
@@ -214,7 +214,6 @@ class Alt(datasets.GeneratorBasedBuilder):
|
|
214 |
urlid = sp[0].replace("URL.", "")
|
215 |
allow_urls[urlid] = {"SNT.URLID": urlid, "url": sp[1]}
|
216 |
|
217 |
-
data = {}
|
218 |
if self.config.name.startswith("alt-parallel"):
|
219 |
data = {}
|
220 |
for lang in self.config.languages:
|
@@ -242,6 +241,9 @@ class Alt(datasets.GeneratorBasedBuilder):
|
|
242 |
if len(sp) >= 2:
|
243 |
data[sntid]["translation"][lang] = sp[1]
|
244 |
|
|
|
|
|
|
|
245 |
elif self.config.name == "alt-en":
|
246 |
data = {}
|
247 |
for fname in ["English-ALT-Draft.txt", "English-ALT-Reviewed.txt"]:
|
@@ -265,6 +267,9 @@ class Alt(datasets.GeneratorBasedBuilder):
|
|
265 |
|
266 |
data[sntid] = d
|
267 |
|
|
|
|
|
|
|
268 |
elif self.config.name == "alt-jp":
|
269 |
data = {}
|
270 |
for fname in ["Japanese-ALT-Draft.txt", "Japanese-ALT-Reviewed.txt"]:
|
@@ -313,8 +318,11 @@ class Alt(datasets.GeneratorBasedBuilder):
|
|
313 |
if sntid in data:
|
314 |
data[sntid][k] = sp[1]
|
315 |
|
|
|
|
|
|
|
316 |
elif self.config.name == "alt-my":
|
317 |
-
|
318 |
for fname in ["data"]:
|
319 |
file_path = os.path.join(basepath, "my-alt-190530", fname)
|
320 |
with open(file_path, encoding="utf-8") as fin:
|
@@ -325,12 +333,13 @@ class Alt(datasets.GeneratorBasedBuilder):
|
|
325 |
if urlid not in allow_urls:
|
326 |
continue
|
327 |
|
328 |
-
|
329 |
"SNT.URLID": urlid,
|
330 |
"SNT.URLID.SNTID": sntid,
|
331 |
"url": allow_urls[urlid]["url"],
|
332 |
"value": sp[1],
|
333 |
}
|
|
|
334 |
|
335 |
elif self.config.name == "alt-km":
|
336 |
data = {}
|
@@ -355,14 +364,16 @@ class Alt(datasets.GeneratorBasedBuilder):
|
|
355 |
}
|
356 |
data[sntid][k] = sp[1]
|
357 |
|
|
|
|
|
|
|
358 |
elif self.config.name == "alt-my-transliteration":
|
359 |
file_path = os.path.join(basepath, "my-en-transliteration", "data.txt")
|
360 |
# Need to set errors='ignore' because of the unknown error
|
361 |
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
|
362 |
# It might due to some issues related to Myanmar alphabets
|
363 |
with open(file_path, encoding="utf-8", errors="ignore") as fin:
|
364 |
-
_id
|
365 |
-
for line in fin:
|
366 |
line = line.strip()
|
367 |
|
368 |
# I don't know why there are \x00 between |||. They don't show in the editor.
|
@@ -373,8 +384,10 @@ class Alt(datasets.GeneratorBasedBuilder):
|
|
373 |
if len(sp) < 2:
|
374 |
continue
|
375 |
|
376 |
-
|
377 |
-
|
|
|
|
|
378 |
|
379 |
elif self.config.name == "alt-my-west-transliteration":
|
380 |
file_path = os.path.join(basepath, "western-myanmar-transliteration", "321.txt")
|
@@ -382,16 +395,12 @@ class Alt(datasets.GeneratorBasedBuilder):
|
|
382 |
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
|
383 |
# It might due to some issues related to Myanmar alphabets
|
384 |
with open(file_path, encoding="utf-8", errors="ignore") as fin:
|
385 |
-
_id
|
386 |
-
for line in fin:
|
387 |
line = line.strip()
|
388 |
line = line.replace("\x00", "")
|
389 |
sp = line.split("|||")
|
390 |
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
for k in data:
|
396 |
-
yield _id, data[k]
|
397 |
-
_id += 1
|
|
|
214 |
urlid = sp[0].replace("URL.", "")
|
215 |
allow_urls[urlid] = {"SNT.URLID": urlid, "url": sp[1]}
|
216 |
|
|
|
217 |
if self.config.name.startswith("alt-parallel"):
|
218 |
data = {}
|
219 |
for lang in self.config.languages:
|
|
|
241 |
if len(sp) >= 2:
|
242 |
data[sntid]["translation"][lang] = sp[1]
|
243 |
|
244 |
+
for _id, item in enumerate(data.values()):
|
245 |
+
yield _id, item
|
246 |
+
|
247 |
elif self.config.name == "alt-en":
|
248 |
data = {}
|
249 |
for fname in ["English-ALT-Draft.txt", "English-ALT-Reviewed.txt"]:
|
|
|
267 |
|
268 |
data[sntid] = d
|
269 |
|
270 |
+
for _id, item in enumerate(data.values()):
|
271 |
+
yield _id, item
|
272 |
+
|
273 |
elif self.config.name == "alt-jp":
|
274 |
data = {}
|
275 |
for fname in ["Japanese-ALT-Draft.txt", "Japanese-ALT-Reviewed.txt"]:
|
|
|
318 |
if sntid in data:
|
319 |
data[sntid][k] = sp[1]
|
320 |
|
321 |
+
for _id, item in enumerate(data.values()):
|
322 |
+
yield _id, item
|
323 |
+
|
324 |
elif self.config.name == "alt-my":
|
325 |
+
_id = 0
|
326 |
for fname in ["data"]:
|
327 |
file_path = os.path.join(basepath, "my-alt-190530", fname)
|
328 |
with open(file_path, encoding="utf-8") as fin:
|
|
|
333 |
if urlid not in allow_urls:
|
334 |
continue
|
335 |
|
336 |
+
yield _id, {
|
337 |
"SNT.URLID": urlid,
|
338 |
"SNT.URLID.SNTID": sntid,
|
339 |
"url": allow_urls[urlid]["url"],
|
340 |
"value": sp[1],
|
341 |
}
|
342 |
+
_id += 1
|
343 |
|
344 |
elif self.config.name == "alt-km":
|
345 |
data = {}
|
|
|
364 |
}
|
365 |
data[sntid][k] = sp[1]
|
366 |
|
367 |
+
for _id, item in enumerate(data.values()):
|
368 |
+
yield _id, item
|
369 |
+
|
370 |
elif self.config.name == "alt-my-transliteration":
|
371 |
file_path = os.path.join(basepath, "my-en-transliteration", "data.txt")
|
372 |
# Need to set errors='ignore' because of the unknown error
|
373 |
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
|
374 |
# It might due to some issues related to Myanmar alphabets
|
375 |
with open(file_path, encoding="utf-8", errors="ignore") as fin:
|
376 |
+
for _id, line in enumerate(fin):
|
|
|
377 |
line = line.strip()
|
378 |
|
379 |
# I don't know why there are \x00 between |||. They don't show in the editor.
|
|
|
384 |
if len(sp) < 2:
|
385 |
continue
|
386 |
|
387 |
+
yield _id, {
|
388 |
+
"en": sp[0].strip(),
|
389 |
+
"my": [sp[1].strip()],
|
390 |
+
}
|
391 |
|
392 |
elif self.config.name == "alt-my-west-transliteration":
|
393 |
file_path = os.path.join(basepath, "western-myanmar-transliteration", "321.txt")
|
|
|
395 |
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
|
396 |
# It might due to some issues related to Myanmar alphabets
|
397 |
with open(file_path, encoding="utf-8", errors="ignore") as fin:
|
398 |
+
for _id, line in enumerate(fin):
|
|
|
399 |
line = line.strip()
|
400 |
line = line.replace("\x00", "")
|
401 |
sp = line.split("|||")
|
402 |
|
403 |
+
yield _id, {
|
404 |
+
"en": sp[0].strip(),
|
405 |
+
"my": [k.strip() for k in sp[1].split("|")],
|
406 |
+
}
|
|
|
|
|
|