albertvillanova HF staff commited on
Commit
52edc12
1 Parent(s): 8a5bfcb
Files changed (1) hide show
  1. alt.py +13 -24
alt.py CHANGED
@@ -216,10 +216,8 @@ class Alt(datasets.GeneratorBasedBuilder):
216
 
217
  data = {}
218
  if self.config.name.startswith("alt-parallel"):
219
- files = self.config.languages
220
-
221
  data = {}
222
- for lang in files:
223
  file_path = os.path.join(basepath, "ALT-Parallel-Corpus-20191206", f"data_{lang}.txt")
224
  with open(file_path, encoding="utf-8") as fin:
225
  for line in fin:
@@ -227,16 +225,18 @@ class Alt(datasets.GeneratorBasedBuilder):
227
  sp = line.split("\t")
228
 
229
  _, urlid, sntid = sp[0].split(".")
230
- sntid = sntid.strip() # Some lines have a trailing blank space: "SNT.102053.5598 " in data_fil.txt
 
231
  if urlid not in allow_urls:
232
  continue
233
 
234
  if sntid not in data:
235
- data[sntid] = {}
236
- data[sntid]["SNT.URLID"] = urlid
237
- data[sntid]["SNT.URLID.SNTID"] = sntid
238
- data[sntid]["url"] = allow_urls[urlid]["url"]
239
- data[sntid]["translation"] = {}
 
240
 
241
  # Note that Japanese and Myanmar texts have empty sentence fields in this release.
242
  if len(sp) >= 2:
@@ -259,15 +259,10 @@ class Alt(datasets.GeneratorBasedBuilder):
259
  "SNT.URLID": urlid,
260
  "SNT.URLID.SNTID": sntid,
261
  "url": allow_urls[urlid]["url"],
262
- "status": None,
263
  "value": sp[1],
264
  }
265
 
266
- if fname == "English-ALT-Draft.txt":
267
- d["status"] = "draft"
268
- else:
269
- d["status"] = "reviewed"
270
-
271
  data[sntid] = d
272
 
273
  elif self.config.name == "alt-jp":
@@ -287,16 +282,12 @@ class Alt(datasets.GeneratorBasedBuilder):
287
  "SNT.URLID.SNTID": sntid,
288
  "url": allow_urls[urlid]["url"],
289
  "value": sp[1],
290
- "status": None,
291
  "word_alignment": None,
292
  "en_tokenized": None,
293
  "jp_tokenized": None,
294
  }
295
 
296
- if fname == "Japanese-ALT-Draft.txt":
297
- d["status"] = "draft"
298
- else:
299
- d["status"] = "reviewed"
300
  data[sntid] = d
301
 
302
  keys = {
@@ -354,9 +345,7 @@ class Alt(datasets.GeneratorBasedBuilder):
354
  continue
355
 
356
  k = "km_pos_tag" if fname == "data_km.km-tag.nova" else "km_tokenized"
357
- if sntid in data:
358
- data[sntid][k] = sp[1]
359
- else:
360
  data[sntid] = {
361
  "SNT.URLID": urlid,
362
  "SNT.URLID.SNTID": sntid,
@@ -364,7 +353,7 @@ class Alt(datasets.GeneratorBasedBuilder):
364
  "km_pos_tag": None,
365
  "km_tokenized": None,
366
  }
367
- data[sntid][k] = sp[1]
368
 
369
  elif self.config.name == "alt-my-transliteration":
370
  file_path = os.path.join(basepath, "my-en-transliteration", "data.txt")
 
216
 
217
  data = {}
218
  if self.config.name.startswith("alt-parallel"):
 
 
219
  data = {}
220
+ for lang in self.config.languages:
221
  file_path = os.path.join(basepath, "ALT-Parallel-Corpus-20191206", f"data_{lang}.txt")
222
  with open(file_path, encoding="utf-8") as fin:
223
  for line in fin:
 
225
  sp = line.split("\t")
226
 
227
  _, urlid, sntid = sp[0].split(".")
228
+ # Some lines have a trailing blank space: "SNT.102053.5598 " in data_fil.txt
229
+ sntid = sntid.strip()
230
  if urlid not in allow_urls:
231
  continue
232
 
233
  if sntid not in data:
234
+ data[sntid] = {
235
+ "SNT.URLID": urlid,
236
+ "SNT.URLID.SNTID": sntid,
237
+ "url": allow_urls[urlid]["url"],
238
+ "translation": {},
239
+ }
240
 
241
  # Note that Japanese and Myanmar texts have empty sentence fields in this release.
242
  if len(sp) >= 2:
 
259
  "SNT.URLID": urlid,
260
  "SNT.URLID.SNTID": sntid,
261
  "url": allow_urls[urlid]["url"],
262
+ "status": "draft" if fname == "English-ALT-Draft.txt" else "reviewed",
263
  "value": sp[1],
264
  }
265
 
 
 
 
 
 
266
  data[sntid] = d
267
 
268
  elif self.config.name == "alt-jp":
 
282
  "SNT.URLID.SNTID": sntid,
283
  "url": allow_urls[urlid]["url"],
284
  "value": sp[1],
285
+ "status": "draft" if fname == "Japanese-ALT-Draft.txt" else "reviewed",
286
  "word_alignment": None,
287
  "en_tokenized": None,
288
  "jp_tokenized": None,
289
  }
290
 
 
 
 
 
291
  data[sntid] = d
292
 
293
  keys = {
 
345
  continue
346
 
347
  k = "km_pos_tag" if fname == "data_km.km-tag.nova" else "km_tokenized"
348
+ if sntid not in data:
 
 
349
  data[sntid] = {
350
  "SNT.URLID": urlid,
351
  "SNT.URLID.SNTID": sntid,
 
353
  "km_pos_tag": None,
354
  "km_tokenized": None,
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")