daza | e3bc92e | 2020-11-04 11:06:26 +0100 | [diff] [blame^] | 1 | # TODO: write a client to make multiple requests to the server! |
| 2 | import subprocess, json, time |
| 3 | import requests, glob, logging |
| 4 | import os.path, sys |
| 5 | from lib.CoNLL_Annotation import get_token_type |
| 6 | import my_utils.file_utils as fu |
| 7 | import argparse |
| 8 | |
| 9 | |
| 10 | TIGER_CORPUS = "/home/daza/datasets/TIGER_conll/tiger_release_aug07.corrected.16012013.conll09" |
| 11 | DE_GSD_CORPUS = "/home/daza/datasets/ud-treebanks-v2.2/UD_German-GSD/de_gsd-ud-test.conllu" |
| 12 | |
| 13 | |
| 14 | if __name__ == "__main__": |
| 15 | |
| 16 | """ |
| 17 | EXECUTE: |
| 18 | |
| 19 | python systems/parse_turku.py --corpus_name DE_GSD --gld_token_type CoNLLUP_Token \ |
| 20 | -i /home/daza/datasets/ud-treebanks-v2.2/UD_German-GSD/de_gsd-ud-test.conllu |
| 21 | |
| 22 | """ |
| 23 | |
| 24 | parser = argparse.ArgumentParser() |
| 25 | parser.add_argument("-i", "--input_file", help="Input Corpus", required=True) |
| 26 | parser.add_argument("-n", "--corpus_name", help="Corpus Name", default="Corpus") |
| 27 | parser.add_argument("-gtt", "--gld_token_type", help="CoNLL Format of the Gold Data", default="CoNLL09_Token") |
| 28 | parser.add_argument("-c", "--comment_str", help="CoNLL Format of comentaries inside the file", default="#") |
| 29 | args = parser.parse_args() |
| 30 | |
| 31 | file_has_next, chunk_ix = True, 0 |
| 32 | CHUNK_SIZE = 10000 |
| 33 | |
| 34 | # ===================================================================================== |
| 35 | # LOGGING INFO ... |
| 36 | # ===================================================================================== |
| 37 | logger = logging.getLogger(__name__) |
| 38 | console_hdlr = logging.StreamHandler(sys.stdout) |
| 39 | file_hdlr = logging.FileHandler(filename=f"logs/Parse_{args.corpus_name}_Turku.log") |
| 40 | logging.basicConfig(level=logging.INFO, handlers=[console_hdlr, file_hdlr]) |
| 41 | logger.info(f"Chunking TIGER Corpus in chunks of {CHUNK_SIZE} Sentences") |
| 42 | |
| 43 | # ===================================================================================== |
| 44 | # PROCESS (PARSE) TIGER Corpus ... |
| 45 | # ===================================================================================== |
| 46 | start = time.time() |
| 47 | total_processed_sents = 0 |
| 48 | line_generator = fu.file_generator(args.input_file) |
| 49 | while file_has_next: |
| 50 | raw_text, file_has_next, n_sents = fu.get_file_chunk(line_generator, chunk_size=CHUNK_SIZE, token_class=get_token_type(args.gld_token_type), comment_str=args.comment_str) |
| 51 | total_processed_sents += n_sents |
| 52 | if len(raw_text) > 0: |
| 53 | fu.turku_parse_file(raw_text, args.input_file, chunk_ix) |
| 54 | now = time.time() |
| 55 | elapsed = (now - start) |
| 56 | logger.info(f"Time Elapsed: {elapsed}. Processed {total_processed_sents}. [{total_processed_sents/elapsed} Sents/sec]\n") # Toks/Sec??? |
| 57 | chunk_ix += 1 |
| 58 | if chunk_ix == 10: break |
| 59 | end = time.time() |
| 60 | logger.info(f"Processing File {args.corpus_name} took {(end - start)} seconds!") |
| 61 | |
| 62 | |