blob: d5656e822589e0dd096bc6a39da5dac7af2cd832 [file] [log] [blame]
dazaff42f632020-10-08 14:46:32 +02001import argparse
dazae3bc92e2020-11-04 11:06:26 +01002from lib.CoNLL_Annotation import read_conll_generator, get_token_type
dazaff42f632020-10-08 14:46:32 +02003
4# TODO: Parallelize this for HUGE Files: All sentences can be processed independently
5
6if __name__ == "__main__":
7 """
8 EXAMPLE:
9 For TreeTagger:
dazae3bc92e2020-11-04 11:06:26 +010010 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
dazaff42f632020-10-08 14:46:32 +020019
20 For RNNTagger
dazae3bc92e2020-11-04 11:06:26 +010021 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
dazaff42f632020-10-08 14:46:32 +020028 """
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)
dazae3bc92e2020-11-04 11:06:26 +010032 parser.add_argument("-t", "--token_type", help="Type of Token of the INPUT file", required=True)
dazaff42f632020-10-08 14:46:32 +020033 parser.add_argument("-ss", "--sent_sep", help="Special separator to distinguish sentence boundaries", default="")
dazae3bc92e2020-11-04 11:06:26 +010034 parser.add_argument("-c", "--com_str", help="Skip line if it starts with this string (comment market)", default="# ")
dazaff42f632020-10-08 14:46:32 +020035 args = parser.parse_args()
36
37 output_file = open(f"{args.src_file}.tok","w")
38
dazae3bc92e2020-11-04 11:06:26 +010039 for conll_obj in read_conll_generator(args.src_file, token_class=get_token_type(args.token_type), comment_str=args.com_str):
dazaff42f632020-10-08 14:46:32 +020040 for tok in conll_obj.tokens:
41 output_file.write(tok.word+"\n")
42 output_file.write(args.sent_sep+"\n")