import os import json import random FILES = { 'CEN': './kgr10/CEN', 'openbooks': './kgr10/openbooks', 'open_science': './kgr10/open_science', 'wikisources-pl': './kgr10/wikisources-pl', 'sejm': './kgr10/sejm/', } def main(): idnum = 0 kgr10 = [] for sname, spath in FILES.items(): for fname in os.listdir(spath): with open(os.path.join(spath, fname), 'rt') as fin: content = fin.readlines() content = "\n".join(content).strip() kgr10.append( json.dumps( { 'id': idnum, 'corpora': sname.strip(), 'filename': fname.strip(), 'text': content } ) ) idnum += 1 random.shuffle(kgr10) with open('./kgr10.jsonl', 'wt') as fout: for kgr10_item in kgr10: fout.write(kgr10_item + "\n") if __name__ == '__main__': main()