import os
from os.path import join, isfile
import re
import numpy as np
import pickle
import argparse
import skipthoughts
import h5py

def main():
	parser = argparse.ArgumentParser()
	#parser.add_argument('--caption_file', type=str, default='Data/sample_captions.txt',
	#				   help='caption file')
	
	parser.add_argument('--caption_file', type=str, default='/media/ssd_working_space/osaid/Data/sample_captions.txt',
					   help='caption file')

	#parser.add_argument('--data_dir', type=str, default='Data',
	#				   help='Data Directory')

	parser.add_argument('--data_dir', type=str, default='/media/ssd_working_space/osaid/Data',
					   help='Data Directory')

	args = parser.parse_args()
	with open( args.caption_file ) as f:
		captions = f.read().split('\n')

	captions = [cap for cap in captions if len(cap) > 0]
	print(captions)
	model = skipthoughts.load_model()
	caption_vectors = skipthoughts.encode(model, captions)

	if os.path.isfile(join(args.data_dir, 'sample_caption_vectors.hdf5')):
		os.remove(join(args.data_dir, 'sample_caption_vectors.hdf5'))
	h = h5py.File(join(args.data_dir, 'sample_caption_vectors.hdf5'))
	h.create_dataset('vectors', data=caption_vectors)		
	h.close()

if __name__ == '__main__':
	main()
[((11, 10, 11, 35), 'argparse.ArgumentParser', 'argparse.ArgumentParser', ({}, {}), '()', False, 'import argparse\n'), ((30, 9, 30, 34), 'skipthoughts.load_model', 'skipthoughts.load_model', ({}, {}), '()', False, 'import skipthoughts\n'), ((31, 19, 31, 55), 'skipthoughts.encode', 'skipthoughts.encode', ({(31, 39, 31, 44): 'model', (31, 46, 31, 54): 'captions'}, {}), '(model, captions)', False, 'import skipthoughts\n'), ((33, 19, 33, 69), 'os.path.join', 'join', ({(33, 24, 33, 37): 'args.data_dir', (33, 39, 33, 68): '"""sample_caption_vectors.hdf5"""'}, {}), "(args.data_dir, 'sample_caption_vectors.hdf5')", False, 'from os.path import join, isfile\n'), ((35, 15, 35, 65), 'os.path.join', 'join', ({(35, 20, 35, 33): 'args.data_dir', (35, 35, 35, 64): '"""sample_caption_vectors.hdf5"""'}, {}), "(args.data_dir, 'sample_caption_vectors.hdf5')", False, 'from os.path import join, isfile\n'), ((34, 12, 34, 62), 'os.path.join', 'join', ({(34, 17, 34, 30): 'args.data_dir', (34, 32, 34, 61): '"""sample_caption_vectors.hdf5"""'}, {}), "(args.data_dir, 'sample_caption_vectors.hdf5')", False, 'from os.path import join, isfile\n')]