Using argparse

This commit is contained in:
Ozbolt Menegatti 2019-02-06 15:28:39 +01:00
parent 3dc69158b9
commit 5b75d6e4fa

26
wani.py
View File

@ -4,6 +4,7 @@ from enum import Enum
from collections import defaultdict from collections import defaultdict
import sys import sys
import logging import logging
import argparse
from msd_translate import MSD_TRANSLATE from msd_translate import MSD_TRANSLATE
@ -11,10 +12,6 @@ from msd_translate import MSD_TRANSLATE
MAX_NUM_COMPONENTS = 5 MAX_NUM_COMPONENTS = 5
STAVKI = sys.argv[1]
STRUKTURE = sys.argv[2]
FILE_OUT = sys.argv[3]
CODES = { CODES = {
"Noun": "N", "Noun": "N",
"Verb": "V", "Verb": "V",
@ -787,11 +784,12 @@ def main():
import time import time
t = time.time() t = time.time()
structures = build_structures(STRUKTURE) structures = build_structures(structures_file)
for s in structures: for s in structures:
logging.debug(str(s)) logging.debug(str(s))
words = load_corpus(STAVKI) logging.info("LOADING TEXT...")
words = load_corpus(input_file)
# import pickle # import pickle
# with open("words.p", "wb") as fp: # with open("words.p", "wb") as fp:
# pickle.dump(words, fp) # pickle.dump(words, fp)
@ -872,10 +870,18 @@ def main():
# print(s.id) # print(s.id)
# print(groups) # print(groups)
if __name__ == '__main__': if __name__ == '__main__':
logging.basicConfig(level=logging.INFO) parser = argparse.ArgumentParser(description='Extract structures from a parsed corpus.')
main() 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? # 6, 7 primeri laznih zadetkov?