return sent_str def format_output(sentences): mode = 'join' output = [] for sent in sentences: if mode == 'join': sent_str = join_affixed_particles(sent[1]) elif mode == 'mark': sent_str = add_affixed_marker(sent[1]) else: raise SyntaxError('mode should either be "join" or "mark"') output.append((sent[0], sent_str)) out = '\n'.join([f'{a[0]},{a[1]}' for a in output]) return out if __name__ == '__main__': pipeline = BoPipeline('dummy', 'pybo', ('pybo_sentences', sentencify), format_output, pybo_profile='GMD') for f in Path('input').glob('*.txt'): pipeline.pipe_file(f, 'output')
output.append({'ex': para_str, 'order': i, 'type': key_type, 'key': key, 'pos': idx}) break output = unique_objects(output, 'ex') return jp.dumps(output) if __name__ == "__main__": pipeline = BoPipeline('dummy', # preprocessor 'pybo', # tokenizer ('pybo_paragraphs', paragraphify), # processor filter_and_format_para, # formatter pybo_profile='GMD') # pybo_profile ap = argparse.ArgumentParser(add_help=False) ap.add_argument("--path", type=str, help="path to corpus") args = ap.parse_args() fns = sorted(glob.glob(os.path.join(args.path, "*"))) for fn in tqdm(fns): pipeline.pipe_file(fn, 'data/toupload') # convert all the ext file to json out_dir = 'data/toupload' out_fns = sorted(glob.glob(os.path.join(out_dir, "*"))) for fn in out_fns: if fn.endswith('.txt'): name, ext = fn.split('.') new_file = '{}.json'.format(name) os.rename(fn, new_file)
sent_str = '' for t in tokens: if t.affix: sent_str += ' ' + t.content else: sent_str += ' ' + t.content return sent_str def format_to_csv(sentences): output = [] for sent in sentences: sent_str = get_sent_str(sent[1]) output.append((sent[0], sent_str)) out = '\n'.join([f'{a[0]},{a[1]}' for a in output]) return out if __name__ == '__main__': pipeline = BoPipeline('dummy', 'pybo', ('pybo_sentences', sentencify), format_to_csv, pybo_profile='GMD') tokens = pipeline.pipe_file('verses.txt', 'lighttag') # in_str = 'འདི་ལ་ཡང་གཟུང་བའི་ཆ་ཡོད་ན་ཤེས་པ་ཡོད་ལ་མེད་ན་མེད་དེ། དེ་ལྟ་བས་ན་ལྷན་ཅིག་འབྱུང་བ་དེ་གཉིས་ཀྱང་རྒྱུ་དང་རྒྱུ་དང་ལྡན་པ་ཉིད་དུ་འགྲུབ་པོ། །གཏན་ཚིགས་པ་དག་ཅེས་བྱ་བ་ནི་གང་དག་གཏན་ཚིགས་ཀྱི་ཐ་སྙད་འདོགས་པ་དེ་དག་ནི་གཏན་ཚིགས་པ་དག་སྟེ། རྟོག་གེ་བ་ཞེས་བྱ་བའི་ཐ་ཚིག་གོ། །དེ་དང་ལྡན་པ་ཉིད་ཅེས་བྱ་བ་ནི་ཡོད་པ་དང་མེད་པ་དང་ལྡན་པ་ཉིད་དོ། །རྒྱུ་དང་རྒྱུ་དང་ལྡན་པ་ཞེས་བྱ་བ་ནི་རྒྱུ་དང་འབྲས་བུ་དག་ཅེས་བྱ་བའི་དོན་ཏོ། །' # print(pipeline.pipe_str(in_str)) print('ok')
for t in tokens: if t.affix: sent_str += ' ' + t.content else: sent_str += ' ' + t.content return sent_str def format_to_csv(sentences): output = [] for sent in sentences: sent_str = get_sent_str(sent[1]) output.append((sent[0], sent_str)) out = '\n'.join([f'{a[0]},{a[1]}' for a in output]) return out if __name__ == '__main__': pipeline = BoPipeline('dummy', 'pybo', ('pybo_sentences', sentencify), format_sentences_for_lighttag, pybo_profile='GMD') tokens = pipeline.pipe_file('lighttag/totag/mdzangs_blun.txt', 'lighttag/toupload') # in_str = 'འདི་ལ་ཡང་གཟུང་བའི་ཆ་ཡོད་ན་ཤེས་པ་ཡོད་ལ་མེད་ན་མེད་དེ། དེ་ལྟ་བས་ན་ལྷན་ཅིག་འབྱུང་བ་དེ་གཉིས་ཀྱང་རྒྱུ་དང་རྒྱུ་དང་ལྡན་པ་ཉིད་དུ་འགྲུབ་པོ། །གཏན་ཚིགས་པ་དག་ཅེས་བྱ་བ་ནི་གང་དག་གཏན་ཚིགས་ཀྱི་ཐ་སྙད་འདོགས་པ་དེ་དག་ནི་གཏན་ཚིགས་པ་དག་སྟེ། རྟོག་གེ་བ་ཞེས་བྱ་བའི་ཐ་ཚིག་གོ། །དེ་དང་ལྡན་པ་ཉིད་ཅེས་བྱ་བ་ནི་ཡོད་པ་དང་མེད་པ་དང་ལྡན་པ་ཉིད་དོ། །རྒྱུ་དང་རྒྱུ་དང་ལྡན་པ་ཞེས་བྱ་བ་ནི་རྒྱུ་དང་འབྲས་བུ་དག་ཅེས་བྱ་བའི་དོན་ཏོ། །' # print(pipeline.pipe_str(in_str)) print('ok')