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 | |
| 15 | python my_utils/conll_to_tok.py \ |
| 16 | -s /home/daza/datasets/ud-treebanks-v2.2/UD_German-GSD/de_gsd-ud-test.conllu \ |
| 17 | -ss "</S>" \ |
| 18 | --token_type CoNLLUP_Token |
daza | ff42f63 | 2020-10-08 14:46:32 +0200 | [diff] [blame] | 19 | |
| 20 | For RNNTagger |
daza | e3bc92e | 2020-11-04 11:06:26 +0100 | [diff] [blame^] | 21 | python my_utils/conll_to_tok.py \ |
| 22 | -s /home/daza/datasets/TIGER_conll/tiger_release_aug07.corrected.16012013.conll09 \ |
| 23 | --token_type CoNLL09_Token |
| 24 | |
| 25 | python my_utils/conll_to_tok.py \ |
| 26 | -s /home/daza/datasets/ud-treebanks-v2.2/UD_German-GSD/de_gsd-ud-test.conllu \ |
| 27 | --token_type CoNLLUP_Token |
daza | ff42f63 | 2020-10-08 14:46:32 +0200 | [diff] [blame] | 28 | """ |
| 29 | |
| 30 | parser = argparse.ArgumentParser() |
| 31 | 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^] | 32 | 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] | 33 | 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^] | 34 | 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] | 35 | args = parser.parse_args() |
| 36 | |
| 37 | output_file = open(f"{args.src_file}.tok","w") |
| 38 | |
daza | e3bc92e | 2020-11-04 11:06:26 +0100 | [diff] [blame^] | 39 | 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] | 40 | for tok in conll_obj.tokens: |
| 41 | output_file.write(tok.word+"\n") |
| 42 | output_file.write(args.sent_sep+"\n") |