From 5b75d6e4fa169dacf6e0e1236fc4132fe1126c5e Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Wed, 6 Feb 2019 15:28:39 +0100 Subject: [PATCH] Using argparse --- wani.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/wani.py b/wani.py index 2c5d71f..23710f2 100644 --- a/wani.py +++ b/wani.py @@ -4,6 +4,7 @@ from enum import Enum from collections import defaultdict import sys import logging +import argparse from msd_translate import MSD_TRANSLATE @@ -11,10 +12,6 @@ from msd_translate import MSD_TRANSLATE MAX_NUM_COMPONENTS = 5 -STAVKI = sys.argv[1] -STRUKTURE = sys.argv[2] -FILE_OUT = sys.argv[3] - CODES = { "Noun": "N", "Verb": "V", @@ -787,11 +784,12 @@ def main(): import time t = time.time() - structures = build_structures(STRUKTURE) + structures = build_structures(structures_file) for s in structures: logging.debug(str(s)) - words = load_corpus(STAVKI) + logging.info("LOADING TEXT...") + words = load_corpus(input_file) # import pickle # with open("words.p", "wb") as fp: # pickle.dump(words, fp) @@ -872,10 +870,18 @@ def main(): # print(s.id) # print(groups) - - if __name__ == '__main__': - logging.basicConfig(level=logging.INFO) - main() + parser = argparse.ArgumentParser(description='Extract structures from a parsed corpus.') + parser.add_argument('input', help='input xml file in `ssj500k form`') + parser.add_argument('structures', help='Structures definitions in xml file') + parser.add_argument('--output', help='Output file (if none given, then output to stdout)') + + parser.add_argument('--lemma_only', help='Will not write word ids, forms and msds in output', action='store_true') + parser.add_argument('--without-rep', help='Will not write representtaions in output', action='store_true') + parser.add_argument('--group', help='Group collocations with same collocation ID', action='store_true') + parser.add_argument('--verbose', help='Enable verbose output to stderr', choices=["warning", "info", "debug"], default="info") + + args = parser.parse_args() + logging.basicConfig(stream=sys.stderr, level=args.verbose.upper()) # 6, 7 primeri laznih zadetkov?