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)
评论列表
文章目录