python配置檔案(ArgumentParser)
阿新 • • 發佈:2019-01-03
配置檔案bash寫的shell檔案:
#!/usr/bin/env bash
for dimension_size in 50 51
do
for iteration_count in 20 21
do
export PYTHONPATH=/home/vineet/semeval2017-task5 && \
/usr/bin/python2.7 /home/v2john/PycharmProjects/semeval2017-task5/semeval_doc2vec_hl.py \
--train_headlines_data_path /home/ubuntu/nlpTools/semeval2017task5/corpus/Headline_Trainingdata.json \
--test_headlines_data_path /home/ubuntu/nlpTools/semeval2017task5/corpus/subtask-2 /Headline_Trialdata.json \
--results_file /home/ubuntu/nlpTools/semeval2017task5/corpus/results_`/bin/date +%Y%m%d`.txt \
--docvec_dimension_size ${dimension_size} \
--docvec_iteration_count ${iteration_count}
done
done
解析檔案:
import sys
from argparse import ArgumentParser
from processors.fpb_docvec_processor import FPBDocvecProcessor
from utils.options import Options
def main(argv):
"""
Main function to kick start execution
:param argv:
:return: null
"""
options = parse_args(argv)
processor = FPBDocvecProcessor(options)
processor.process()
def parse_args(argv):
"""
Parses command line arguments form an options object
:param argv:
:return:
"""
parser = ArgumentParser(prog="semeval2015-task5")
parser.add_argument('--train_headlines_data_path', metavar='FPB Sentences File Path',
type=str, required=True)
parser.add_argument('--test_headlines_data_path', metavar='Test Headlines File Path',
type=str, required=True)
parser.add_argument('--docvec_dimension_size', metavar='Dimensions for Doc2Vec',
type=int)
parser.add_argument('--docvec_iteration_count', metavar='Iterations for Doc2Vec',
type=int)
parser.add_argument('--results_file', metavar='File to post results to',
type=str)
return parser.parse_args(argv, namespace=Options)
if __name__ == "__main__":
main(sys.argv[1:])