news_evaluation.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:attention-nmt 作者: palak-jain 项目源码 文件源码
def get_options():
    '''
    Extracts command line arguments
    '''
    input_fname = None
    output_fname = None
    test_fname = None
    max_candidates = MAX_CANDIDATES
    check_only = False
    silent = False

    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], 'hi:o:t:', 
        ['help', 'input-file=', 'output-file=', 'test-file=',
         'check-only', 'silent'])
    except getopt.GetoptError, err:
        sys.stderr.write('Error: %s\n' % err)
        usage()
        sys.exit(1)

    for o, a in opts:
        if o in ('-i', '--input-file'):
            input_fname = a
        elif o in ('-o', '--output-file'):
            output_fname = a
        elif o in ('-t', '--test-file'):
            test_fname = a   
        elif o in ('-h', '--help'):
            usage()
            sys.exit()
        elif o in ('--check-only',):
            check_only = True
        elif o in ('--silent',):
            silent = True
        elif o in ('--max-candidates', ):
            try:
                max_candidates = int(a)
            except ValueError, e:
                sys.stderr.write('Error: --max-candidates takes integer argument (you provided %s).\n' % a)
                sys.exit(1)
            if max_candidates < 1:
                sys.stderr.write('Error: --max-candidates must be above 0.\n')
                sys.exit(1)

        else:
            sys.stderr.write('Error: unknown option %s. Type --help to see the options.\n' % o)
            sys.exit(1)

    if check_only:
        if test_fname or output_fname:
            sys.stderr.write('No test file or output file is required to check the input format.\n')
            sys.exit(1)
    else:   
        if not test_fname:
            sys.stderr.write('Error: no test file provided.\n')
            sys.exit(1)

    return input_fname, output_fname, test_fname, max_candidates, check_only, silent
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号