# Path: preimage/features/string_feature_space.py
# 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)
#     index_pointers, indexes, data = __initialize_pointers_indexes_data(n_examples)
#     __build_pointers_indexes_data_with_positions(index_pointers, indexes, data, n, n_gram_to_index, Y)
#     n_columns = __get_n_columns(n, len(n_gram_to_index), Y)
#     feature_space = __build_csr_matrix(index_pointers, indexes, data, n_examples, n_columns)
#     return feature_space


import numpy
from preimage.features.string_feature_space import build_feature_space_with_positions
    Creates a sparse matrix representation of the n-grams in each training string. The representation takes in account
    the positions of the n-grams in the strings, This is used to compute the weights of the graph during the inference
    phase.

    Attributes
    ----------
    n : int
        N-gram length.
    max_n_gram_count : int
        Number of n-grams in the training string of highest length.
    feature_space : sparse matrix, shape = [n_samples, max_n_gram_count * len(alphabet)**n]
        Sparse matrix representation of the n-grams in each training string, where n_samples is the number of training
        samples.
    """
    def __init__(self, alphabet, n, Y, is_normalized):
        """Create the output feature space for the Weighted Degree kernel

        Parameters
        ----------
        alphabet : list
            list of letters
        n : int
            n-gram length
        Y : array, [n_samples, ]
            The training strings.
        is_normalized : bool
            True if the feature space should be normalized, False otherwise.
        """
        self.n = int(n)
        self._alphabet_n_gram_count = len(alphabet) ** n

# Path: preimage/features/string_feature_space.py
# 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)
#     index_pointers, indexes, data = __initialize_pointers_indexes_data(n_examples)
#     __build_pointers_indexes_data_with_positions(index_pointers, indexes, data, n, n_gram_to_index, Y)
#     n_columns = __get_n_columns(n, len(n_gram_to_index), Y)
#     feature_space = __build_csr_matrix(index_pointers, indexes, data, n_examples, n_columns)
#     return feature_space


# Path: preimage/features/weighted_degree_feature_space.py
import numpy
from preimage.features.string_feature_space import build_feature_space_with_positions

    Creates a sparse matrix representation of the n-grams in each training string. The representation takes in account
    the positions of the n-grams in the strings, This is used to compute the weights of the graph during the inference
    phase.

    Attributes
    ----------
    n : int
        N-gram length.
    max_n_gram_count : int
        Number of n-grams in the training string of highest length.
    feature_space : sparse matrix, shape = [n_samples, max_n_gram_count * len(alphabet)**n]
        Sparse matrix representation of the n-grams in each training string, where n_samples is the number of training
        samples.
    """
    def __init__(self, alphabet, n, Y, is_normalized):
        """Create the output feature space for the Weighted Degree kernel

        Parameters
        ----------
        alphabet : list
            list of letters
        n : int
            n-gram length
        Y : array, [n_samples, ]
            The training strings.
        is_normalized : bool
            True if the feature space should be normalized, False otherwise.
        """
        self.n = int(n)
        self._alphabet_n_gram_count = len(alphabet) ** n

        self.feature_space = build_feature_space_with_positions(alphabet, self.n, Y)