trainer.py 文件源码

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

项目:shaman 作者: Prev 项目源码 文件源码
def run() :
    if len(sys.argv) != 3 :
        # Exception handling on starting program
        print('Usage: "shaman-trainer <code_bunch.csv> <result.json>"')
        sys.exit(-1)


    # Args
    codebunch_file = sys.argv[1]
    result_file = sys.argv[2]


    if not os.path.isfile(codebunch_file) :
        # Exception handling of <code bunch> file
        print('"%s" is not a file' % codebunch_file)
        sys.exit(-1)



    # Read CSV file
    csv.field_size_limit(sys.maxsize) # Set CSV limit to sys.maxsize
    filedata = []

    print('Load CSV file')

    with open(codebunch_file) as csvfile :
        reader = csv.reader(csvfile, delimiter=',')
        for row in reader :
            filedata.append(row)


    # Fetch keyword data
    trained_data = {}
    trained_data['keywords'] = fetch_keywords(filedata)
    trained_data['patterns'] = match_patterns(filedata)

    # Save result
    with open(result_file, 'w') as file :
        file.write( json.dumps(trained_data) )

    print('Trained result is saved at "%s"' % result_file)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号