# Path: preimage/utils/alphabet.py
# def get_n_gram_to_index(alphabet, n):
#     n_grams = get_n_grams(alphabet, n)
#     indexes = numpy.arange(len(n_grams))
#     n_gram_to_index = dict(zip(n_grams, indexes))
#     return n_gram_to_index
# 
# Path: preimage/exceptions/n_gram.py
# class InvalidNGramError(ValueError):
#     def __init__(self, n, n_gram):
#         self.n = n
#         self.n_gram = n_gram
# 
#     def __str__(self):
#         error_message = "{} is not a possible {:d}_gram for this alphabet".format(self.n_gram, self.n)
#         return error_message


from collections import Counter
from scipy.sparse import csr_matrix
from preimage.utils.alphabet import get_n_gram_to_index
from preimage.exceptions.n_gram import InvalidNGramError
import numpy
    n_gram_counter = Counter(y_n_gram_indexes)
    data = [n_gram_counter[index] for index in unique_n_gram_indexes]
    return data


def __build_csr_matrix(index_pointers, indexes, data, n_rows, n_columns):
    return csr_matrix((numpy.array(data), numpy.array(indexes), numpy.array(index_pointers)),
                      shape=(n_rows, n_columns), dtype=numpy.float)


def build_feature_space_with_positions(alphabet, n, Y):
    """Create the feature space by considering the position of the n-gram in the strings

    Parameters
    ----------
    alphabet : list
        list of letters
    n : int
        n-gram length
    Y : array, [n_samples, ]
        The training strings.

    Returns
    -------
    feature_space : sparse matrix, shape = [n_samples, max_n_gram_count * len(alphabet)**n]
        Sparse matrix representation of the n-grams in each string of Y, where n_samples is the number of training
        samples and max_n_gram_count is the number of n-gram in the highest length string of Y.
    """
    n = int(n)
    n_examples = numpy.array(Y).shape[0]

# Path: preimage/utils/alphabet.py
# def get_n_gram_to_index(alphabet, n):
#     n_grams = get_n_grams(alphabet, n)
#     indexes = numpy.arange(len(n_grams))
#     n_gram_to_index = dict(zip(n_grams, indexes))
#     return n_gram_to_index
# 
# Path: preimage/exceptions/n_gram.py
# class InvalidNGramError(ValueError):
#     def __init__(self, n, n_gram):
#         self.n = n
#         self.n_gram = n_gram
# 
#     def __str__(self):
#         error_message = "{} is not a possible {:d}_gram for this alphabet".format(self.n_gram, self.n)
#         return error_message


# Path: preimage/features/string_feature_space.py
from collections import Counter
from scipy.sparse import csr_matrix
from preimage.utils.alphabet import get_n_gram_to_index
from preimage.exceptions.n_gram import InvalidNGramError
import numpy

    n_gram_counter = Counter(y_n_gram_indexes)
    data = [n_gram_counter[index] for index in unique_n_gram_indexes]
    return data


def __build_csr_matrix(index_pointers, indexes, data, n_rows, n_columns):
    return csr_matrix((numpy.array(data), numpy.array(indexes), numpy.array(index_pointers)),
                      shape=(n_rows, n_columns), dtype=numpy.float)


def build_feature_space_with_positions(alphabet, n, Y):
    """Create the feature space by considering the position of the n-gram in the strings

    Parameters
    ----------
    alphabet : list
        list of letters
    n : int
        n-gram length
    Y : array, [n_samples, ]
        The training strings.

    Returns
    -------
    feature_space : sparse matrix, shape = [n_samples, max_n_gram_count * len(alphabet)**n]
        Sparse matrix representation of the n-grams in each string of Y, where n_samples is the number of training
        samples and max_n_gram_count is the number of n-gram in the highest length string of Y.
    """
    n = int(n)
    n_examples = numpy.array(Y).shape[0]

    n_gram_to_index = get_n_gram_to_index(alphabet, n)