from keras import layers
from keras.models import Sequential
from six.moves import range

from constants import INVERT
from data_gen import LazyDataLoader
from utils import colors
from utils import get_chars_and_ctable

ls -alrt

DATA_LOADER = LazyDataLoader()

INPUT_MAX_LEN, OUTPUT_MAX_LEN, TRAINING_SIZE = DATA_LOADER.statistics()

chars, ctable = get_chars_and_ctable()

if not os.path.exists('x_y.npz'):
    raise Exception('Please run the vectorization script before.')

print('Loading data from prefetch...')
data = np.load('x_y.npz')
x_train = data['x_train']
x_val = data['x_val']
y_train = data['y_train']
y_val = data['y_val']

print('x_train[0]:', x_train[0])
print('y_train[0]:', x_train[0])

print('Training Data:')
from random import randint, choice

import numpy as np

from utils import get_chars_and_ctable

VOCABULARY, _ = get_chars_and_ctable()


def add_char_randomly(input_str, vocabulary='abcdefghijklmnopqrstuvwxy'):
    random_char = choice(list(vocabulary))
    i = randint(a=0, b=len(input_str) - 1)
    output_str = input_str[0:i] + random_char + input_str[i:]
    assert len(output_str) == len(input_str) + 1
    assert random_char in output_str
    return output_str


def remove_char_randomly(input_str):
    i = randint(a=0, b=len(input_str) - 1)
    char_to_remove = input_str[i]
    before = input_str.count(char_to_remove)
    output_str = input_str[0:i] + input_str[i + 1:]
    after = output_str.count(char_to_remove)
    assert before - 1 == after
    assert len(output_str) == len(input_str) - 1
    return output_str


def change_char_randomly(input_str, vocabulary='abcdefghijklmnopqrstuvwxy'):
    random_char = choice(list(vocabulary))