Datasets:

License:
DCNemesis commited on
Commit
8a9924d
1 Parent(s): 1837f91

fix alignment of resources with text

Browse files
Files changed (1) hide show
  1. biblenlp-corpus.py +14 -10
biblenlp-corpus.py CHANGED
@@ -292,16 +292,18 @@ class BiblenlpCorpus(datasets.GeneratorBasedBuilder):
292
  trans_dict[lang]=list(trans_texts[lang].values())
293
 
294
  single_file = {x:list(single_texts[x].keys()) for x in langs}
 
 
295
  single_lic_list =[]
296
  single_copy_list = []
297
- for lang in langs:
298
- single_lic_list.extend([trans_license.get(x,'') for x in single_file[lang]])
299
- single_copy_list.extend([trans_copyright.get(x,'') for x in single_file[lang]])
300
  if all([single_dict.get(x) and single_dict.get(x) != [{}] and list(single_dict.get(x)) for x in langs]) and len(list(single_dict.keys())) == len(langs) and self.config.pair != 'range':
301
  id = id + 1
302
  sfile_list = []
303
- for key in langs:
304
- for value in single_file.get(key):
305
  sfile_list.append({'lang':key,'file':value})
306
 
307
  #print('outputting single example')
@@ -313,18 +315,20 @@ class BiblenlpCorpus(datasets.GeneratorBasedBuilder):
313
  raise
314
 
315
  file_list = {x:list(trans_texts[x].keys()) for x in langs}
 
 
316
  #license_list = [trans_license.get(x,'') for x in [y for y in file_list.values()]]
317
  #copyright_list = [trans_copyright.get(x,'') for x in [y for y in file_list.values()]]
318
  license_list = []
319
  copyright_list = []
320
- for lang in langs:
321
- license_list.extend([trans_license.get(x,'') for x in file_list[lang]])
322
- copyright_list .extend([trans_copyright.get(x,'') for x in file_list[lang]])
323
  if len(o_group)>1 and all([trans_dict.get(x) and trans_dict.get(x) != [{}] and list(trans_dict.get(x)) for x in langs]) and len(list(trans_dict.keys())) == len(langs) and self.config.pair != 'single':
324
  id = id + 1
325
  ofile_list = []
326
- for key in langs:
327
- for value in file_list.get(key):
328
  ofile_list.append({'lang':key,'file':value})
329
  #print('outputting range example')
330
  try:
 
292
  trans_dict[lang]=list(trans_texts[lang].values())
293
 
294
  single_file = {x:list(single_texts[x].keys()) for x in langs}
295
+ sing_v_order = {x:np.argsort(list(single_texts[x].values())) for x in langs}
296
+ lang_order = np.argsort(langs)
297
  single_lic_list =[]
298
  single_copy_list = []
299
+ for lang in [langs[x] for x in lang_order]:
300
+ single_lic_list.extend([trans_license.get(single_file[lang][x],'') for x in sing_v_order[lang]])
301
+ single_copy_list.extend([trans_copyright.get(single_file[lang][x],'') for x in sing_v_order[lang]])
302
  if all([single_dict.get(x) and single_dict.get(x) != [{}] and list(single_dict.get(x)) for x in langs]) and len(list(single_dict.keys())) == len(langs) and self.config.pair != 'range':
303
  id = id + 1
304
  sfile_list = []
305
+ for key in [langs[x] for x in lang_order]:
306
+ for value in [single_file.get(key)[x] for x in sing_v_order.get(key)]:
307
  sfile_list.append({'lang':key,'file':value})
308
 
309
  #print('outputting single example')
 
315
  raise
316
 
317
  file_list = {x:list(trans_texts[x].keys()) for x in langs}
318
+ trans_v_order = {x:np.argsort(list(trans_texts[x].values())) for x in langs}
319
+ lang_order = np.argsort(langs)
320
  #license_list = [trans_license.get(x,'') for x in [y for y in file_list.values()]]
321
  #copyright_list = [trans_copyright.get(x,'') for x in [y for y in file_list.values()]]
322
  license_list = []
323
  copyright_list = []
324
+ for lang in [langs[x] for x in lang_order]:
325
+ license_list.extend([trans_license.get(file_list[lang][x],'') for x in trans_v_order[lang]])
326
+ copyright_list .extend([trans_copyright.get(file_list[lang][x],'') for x in trans_v_order[lang]])
327
  if len(o_group)>1 and all([trans_dict.get(x) and trans_dict.get(x) != [{}] and list(trans_dict.get(x)) for x in langs]) and len(list(trans_dict.keys())) == len(langs) and self.config.pair != 'single':
328
  id = id + 1
329
  ofile_list = []
330
+ for key in [langs[x] for x in lang_order]:
331
+ for value in [file_list.get(key)[x] for x in trans_v_order.get(key)]:
332
  ofile_list.append({'lang':key,'file':value})
333
  #print('outputting range example')
334
  try: