import h5py
import numpy as np

train_dataset0 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_00.hdf5', 'r')
train_dataset1 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_01.hdf5', 'r')
train_dataset2 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_02.hdf5', 'r')
train_dataset3 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_03.hdf5', 'r')
train_dataset4 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_04.hdf5', 'r')
train_dataset5 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_05.hdf5', 'r')
train_dataset6 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_06.hdf5', 'r')
train_dataset7 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_07.hdf5', 'r')
train_dataset8 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_08.hdf5', 'r')
train_dataset9 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_09.hdf5', 'r')
train_dataset10 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_10.hdf5', 'r')
train_dataset11 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_11.hdf5', 'r')
train_dataset12 = h5py.File('./dataset/image_embeddings_to_sentence/stories_to_index_train_split_12.hdf5', 'r')

image_embeddings0 = np.array(train_dataset0["image_embeddings"])
image_embeddings1 = np.array(train_dataset1["image_embeddings"])
image_embeddings2 = np.array(train_dataset2["image_embeddings"])
image_embeddings3 = np.array(train_dataset3["image_embeddings"])
image_embeddings4 = np.array(train_dataset4["image_embeddings"])
image_embeddings5 = np.array(train_dataset5["image_embeddings"])
image_embeddings6 = np.array(train_dataset6["image_embeddings"])
image_embeddings7 = np.array(train_dataset7["image_embeddings"])
image_embeddings8 = np.array(train_dataset8["image_embeddings"])
image_embeddings9 = np.array(train_dataset9["image_embeddings"])
image_embeddings10 = np.array(train_dataset10["image_embeddings"])
image_embeddings11 = np.array(train_dataset11["image_embeddings"])
image_embeddings12 = np.array(train_dataset12["image_embeddings"])

merged_array = np.append(image_embeddings0, image_embeddings1, axis = 0)
merged_array = np.append(merged_array, image_embeddings2, axis = 0)
merged_array = np.append(merged_array, image_embeddings3, axis = 0)
merged_array = np.append(merged_array, image_embeddings4, axis = 0)
merged_array = np.append(merged_array, image_embeddings5, axis = 0)
merged_array = np.append(merged_array, image_embeddings6, axis = 0)
#merged_array = np.append(merged_array, image_embeddings7, axis = 0)
#merged_array = np.append(merged_array, image_embeddings8, axis = 0)
#merged_array = np.append(merged_array, image_embeddings9, axis = 0)
#merged_array = np.append(merged_array, image_embeddings10, axis = 0)
#merged_array = np.append(merged_array, image_embeddings11, axis = 0)
#merged_array = np.append(merged_array, image_embeddings12, axis = 0)

story_sentences0 = np.array(train_dataset0["story_sentences"])
story_sentences1 = np.array(train_dataset1["story_sentences"])
story_sentences2 = np.array(train_dataset2["story_sentences"])
story_sentences3 = np.array(train_dataset3["story_sentences"])
story_sentences4 = np.array(train_dataset4["story_sentences"])
story_sentences5 = np.array(train_dataset5["story_sentences"])
story_sentences6 = np.array(train_dataset6["story_sentences"])
#story_sentences7 = np.array(train_dataset7["story_sentences"])
#story_sentences8 = np.array(train_dataset8["story_sentences"])
#story_sentences9 = np.array(train_dataset9["story_sentences"])
#story_sentences10 = np.array(train_dataset10["story_sentences"])
#story_sentences11 = np.array(train_dataset11["story_sentences"])
#story_sentences12 = np.array(train_dataset12["story_sentences"])

merged_array_sents = np.append(story_sentences0, story_sentences1, axis = 0)
merged_array_sents = np.append(merged_array_sents, story_sentences2, axis = 0)
merged_array_sents = np.append(merged_array_sents, story_sentences3, axis = 0)
merged_array_sents = np.append(merged_array_sents, story_sentences4, axis = 0)
merged_array_sents = np.append(merged_array_sents, story_sentences5, axis = 0)
merged_array_sents = np.append(merged_array_sents, story_sentences6, axis = 0)
#merged_array_sents = np.append(merged_array_sents, story_sentences7, axis = 0)
#merged_array_sents = np.append(merged_array_sents, story_sentences8, axis = 0)
#merged_array_sents = np.append(merged_array_sents, story_sentences9, axis = 0)
#merged_array_sents = np.append(merged_array_sents, story_sentences10, axis = 0)
#merged_array_sents = np.append(merged_array_sents, story_sentences11, axis = 0)
#merged_array_sents = np.append(merged_array_sents, story_sentences12, axis = 0)

h5f = h5py.File('img_embeds.h5', 'w')
h5f.create_dataset('dataset_1', data=merged_array)

h5f.close()

h5f = h5py.File('sent_embeds.h5', 'w')
h5f.create_dataset('dataset_1', data=merged_array_sents)

h5f.close()

#h5f = h5py.File('data.h5','r')
#merged_hdf5 = h5f['dataset_1'][:]
#h5f.close()

#print(merged_hdf5.shape)