# Path: preimage/utils/alphabet.py
# def transform_strings_to_integer_lists(Y, alphabet):
#     letter_to_int = get_n_gram_to_index(alphabet, 1)
#     n_examples = numpy.array(Y).shape[0]
#     max_length = numpy.max([len(y) for y in Y])
#     Y_int = numpy.zeros((n_examples, max_length), dtype=numpy.int8) - 1
#     for y_index, y in enumerate(Y):
#         for letter_index, letter in enumerate(y):
#             Y_int[y_index, letter_index] = letter_to_int[letter]
#     return Y_int
# 
# def get_n_grams(alphabet, n):
#     n = int(n)
#     if n <= 0:
#         raise InvalidNGramLengthError(n)
#     n_grams = [''.join(n_gram) for n_gram in product(alphabet, repeat=n)]
#     return n_grams


import numpy
from preimage.features.gs_similarity_weights import compute_gs_similarity_weights
from preimage.utils.alphabet import transform_strings_to_integer_lists, get_n_grams
__author__ = 'amelie'



# Shouldn't label this as "feature-space" since we don't use a sparse matrix representation here.
class GenericStringSimilarityFeatureSpace:
    """Output space for the Generic String kernel with position and n-gram similarity.

    Doesn't use a sparse matrix representation because it takes in account the similarity between the n-grams.
    This is used to compute the weights of the graph during the inference phase.

    Attributes
    ----------
    n : int
        N-gram length.
    is_normalized : bool
        True if the feature space should be normalized, False otherwise.
    max_train_length : int
        Length of the longest string in the training dataset.
    gs_kernel : GenericStringKernel
        Generic string kernel.
    """

    def __init__(self, alphabet, n, Y, is_normalized, gs_kernel):
        self.n = int(n)
        self.is_normalized = is_normalized
        self._y_lengths = numpy.array([len(y) for y in Y])
        self.max_train_length = numpy.max(self._y_lengths)
        self.gs_kernel = gs_kernel
        self._Y_int = transform_strings_to_integer_lists(Y, alphabet)

# Path: preimage/utils/alphabet.py
# def transform_strings_to_integer_lists(Y, alphabet):
#     letter_to_int = get_n_gram_to_index(alphabet, 1)
#     n_examples = numpy.array(Y).shape[0]
#     max_length = numpy.max([len(y) for y in Y])
#     Y_int = numpy.zeros((n_examples, max_length), dtype=numpy.int8) - 1
#     for y_index, y in enumerate(Y):
#         for letter_index, letter in enumerate(y):
#             Y_int[y_index, letter_index] = letter_to_int[letter]
#     return Y_int
# 
# def get_n_grams(alphabet, n):
#     n = int(n)
#     if n <= 0:
#         raise InvalidNGramLengthError(n)
#     n_grams = [''.join(n_gram) for n_gram in product(alphabet, repeat=n)]
#     return n_grams


# Path: preimage/features/gs_similarity_feature_space.py
import numpy
from preimage.features.gs_similarity_weights import compute_gs_similarity_weights
from preimage.utils.alphabet import transform_strings_to_integer_lists, get_n_grams

__author__ = 'amelie'



# Shouldn't label this as "feature-space" since we don't use a sparse matrix representation here.
class GenericStringSimilarityFeatureSpace:
    """Output space for the Generic String kernel with position and n-gram similarity.

    Doesn't use a sparse matrix representation because it takes in account the similarity between the n-grams.
    This is used to compute the weights of the graph during the inference phase.

    Attributes
    ----------
    n : int
        N-gram length.
    is_normalized : bool
        True if the feature space should be normalized, False otherwise.
    max_train_length : int
        Length of the longest string in the training dataset.
    gs_kernel : GenericStringKernel
        Generic string kernel.
    """

    def __init__(self, alphabet, n, Y, is_normalized, gs_kernel):
        self.n = int(n)
        self.is_normalized = is_normalized
        self._y_lengths = numpy.array([len(y) for y in Y])
        self.max_train_length = numpy.max(self._y_lengths)
        self.gs_kernel = gs_kernel
        self._Y_int = transform_strings_to_integer_lists(Y, alphabet)

        self._n_grams_int = transform_strings_to_integer_lists(get_n_grams(alphabet, n), alphabet)