daza | ff42f63 | 2020-10-08 14:46:32 +0200 | [diff] [blame] | 1 | import argparse |
daza | e3bc92e | 2020-11-04 11:06:26 +0100 | [diff] [blame] | 2 | from lib.CoNLL_Annotation import read_conll_generator, get_token_type |
daza | ff42f63 | 2020-10-08 14:46:32 +0200 | [diff] [blame] | 3 | |
| 4 | # TODO: Parallelize this for HUGE Files: All sentences can be processed independently |
| 5 | |
| 6 | if __name__ == "__main__": |
| 7 | """ |
| 8 | EXAMPLE: |
| 9 | For TreeTagger: |
daza | e3bc92e | 2020-11-04 11:06:26 +0100 | [diff] [blame] | 10 | python my_utils/conll_to_tok.py \ |
| 11 | -s /home/daza/datasets/TIGER_conll/tiger_release_aug07.corrected.16012013.conll09 \ |
| 12 | -ss "</S>" \ |
| 13 | --token_type CoNLL09_Token |
| 14 | |
daza | d7d7075 | 2021-01-12 18:17:49 +0100 | [diff] [blame^] | 15 | *** GERMAN UNIVERSAL DEPS TEST *** |
| 16 | |
daza | e3bc92e | 2020-11-04 11:06:26 +0100 | [diff] [blame] | 17 | python my_utils/conll_to_tok.py \ |
| 18 | -s /home/daza/datasets/ud-treebanks-v2.2/UD_German-GSD/de_gsd-ud-test.conllu \ |
| 19 | -ss "</S>" \ |
| 20 | --token_type CoNLLUP_Token |
daza | ff42f63 | 2020-10-08 14:46:32 +0200 | [diff] [blame] | 21 | |
daza | d7d7075 | 2021-01-12 18:17:49 +0100 | [diff] [blame^] | 22 | *** TIGER TEST NEW ORTH *** |
| 23 | |
| 24 | python my_utils/conll_to_tok.py \ |
| 25 | -s /home/daza/datasets/TIGER_conll/data_splits/test/Tiger.NewOrth.test.conll \ |
| 26 | -ss "</S>" \ |
| 27 | --token_type CoNLLUP_Token |
| 28 | |
| 29 | |
daza | ff42f63 | 2020-10-08 14:46:32 +0200 | [diff] [blame] | 30 | For RNNTagger |
daza | e3bc92e | 2020-11-04 11:06:26 +0100 | [diff] [blame] | 31 | python my_utils/conll_to_tok.py \ |
| 32 | -s /home/daza/datasets/TIGER_conll/tiger_release_aug07.corrected.16012013.conll09 \ |
| 33 | --token_type CoNLL09_Token |
| 34 | |
| 35 | python my_utils/conll_to_tok.py \ |
| 36 | -s /home/daza/datasets/ud-treebanks-v2.2/UD_German-GSD/de_gsd-ud-test.conllu \ |
| 37 | --token_type CoNLLUP_Token |
daza | ff42f63 | 2020-10-08 14:46:32 +0200 | [diff] [blame] | 38 | """ |
| 39 | |
| 40 | parser = argparse.ArgumentParser() |
| 41 | parser.add_argument("-s", "--src_file", help="CoNLLU File to Convert into the .tok input for RNNTagger/TreeTagger", required=True) |
daza | e3bc92e | 2020-11-04 11:06:26 +0100 | [diff] [blame] | 42 | parser.add_argument("-t", "--token_type", help="Type of Token of the INPUT file", required=True) |
daza | ff42f63 | 2020-10-08 14:46:32 +0200 | [diff] [blame] | 43 | parser.add_argument("-ss", "--sent_sep", help="Special separator to distinguish sentence boundaries", default="") |
daza | e3bc92e | 2020-11-04 11:06:26 +0100 | [diff] [blame] | 44 | parser.add_argument("-c", "--com_str", help="Skip line if it starts with this string (comment market)", default="# ") |
daza | ff42f63 | 2020-10-08 14:46:32 +0200 | [diff] [blame] | 45 | args = parser.parse_args() |
| 46 | |
daza | d7d7075 | 2021-01-12 18:17:49 +0100 | [diff] [blame^] | 47 | if args.sent_sep == "": |
| 48 | output_file = open(f"{args.src_file}.tok","w") |
| 49 | else: |
| 50 | output_file = open(f"{args.src_file}.sep.tok","w") |
daza | ff42f63 | 2020-10-08 14:46:32 +0200 | [diff] [blame] | 51 | |
daza | e3bc92e | 2020-11-04 11:06:26 +0100 | [diff] [blame] | 52 | for conll_obj in read_conll_generator(args.src_file, token_class=get_token_type(args.token_type), comment_str=args.com_str): |
daza | ff42f63 | 2020-10-08 14:46:32 +0200 | [diff] [blame] | 53 | for tok in conll_obj.tokens: |
| 54 | output_file.write(tok.word+"\n") |
| 55 | output_file.write(args.sent_sep+"\n") |