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, 'argparse.ArgumentParser', 'argparse.ArgumentParser', False, 'import argparse\n'), (30, 'skipthoughts.load_model', 'skipthoughts.load_model', False, 'import skipthoughts\n'), (31, 'skipthoughts.encode', 'skipthoughts.encode', False, 'import skipthoughts\n'), (33, 'os.path.join', 'join', False, 'from os.path import join, isfile\n'), (35, 'os.path.join', 'join', False, 'from os.path import join, isfile\n'), (34, 'os.path.join', 'join', False, 'from os.path import join, isfile\n')]