# Path: automlk/context.py
# def text_model_filename(textset_id, model_type, params):
#     """
#     name of the file with params
# 
#     :param model_type: model type (bow, w2v, d2v)
#     :param params: params of the model
#     :return:
#     """
#     folder = get_data_folder() + '/texts/%s' % textset_id
#     if not os.path.exists(folder):
#         os.makedirs(folder)
# 
#     params_name = "-".join([key + '_' + str(params[key]) for key in params.keys()])
#     for c in ['[', ']', ',', '(', ')', '{', '}']:
#         params_name = params_name.replace(c, '')
#     return folder + '/%s-' % model_type + params_name.replace(' ', '_')


from abc import ABCMeta, abstractmethod
from sklearn.preprocessing import StandardScaler, MinMaxScaler, RobustScaler, MaxAbsScaler, Imputer, PolynomialFeatures, \
    LabelEncoder
from sklearn.decomposition import TruncatedSVD, FastICA, PCA
from sklearn.feature_selection import SelectFromModel
from sklearn.svm import LinearSVC, LinearSVR
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
from .spaces.process import *
from .utils.text_encoders import *
from .context import text_model_filename
    from gensim.models import Word2Vec, Doc2Vec
    from gensim.models.doc2vec import TaggedDocument
import numpy as np
import pickle
import pandas as pd
import category_encoders as ce
                encoder = model_doc2vec(X[col].values, self.transformer_params)
            self.feature_names.remove(col)
            self.feature_names += [col + '__' + str(i) for i in range(self.transformer_params['size'])]
            self.transformer.append((col, encoder))

    def transform(self, X):
        # transform X
        for col, encoder in self.transformer:
            T = pd.DataFrame(vector_doc2vec(encoder, X[col].values, self.params)).reset_index(drop=True)
            T.columns = [col + '__' + str(i) for i in range(self.transformer_params['size'])]
            X = pd.concat([X.reset_index(drop=True), T], axis=1)
            # remove col in X
            X.drop(col, axis=1, inplace=True)
        return X


def get_text_encoder(features, col, model_type, params):
    """
    get the encoder from a text column (col), with params

    :param features: list of features of the dataset
    :param col: column name
    :param model_type: model type (bow, w2v, d2v)
    :param params: params of the encoder (size, ...)
    :return: encoder or None
    """
    for f in features:
        if f['name'] == col:
            ref = f['text_ref']
            if ref != '':

# Path: automlk/context.py
# def text_model_filename(textset_id, model_type, params):
#     """
#     name of the file with params
# 
#     :param model_type: model type (bow, w2v, d2v)
#     :param params: params of the model
#     :return:
#     """
#     folder = get_data_folder() + '/texts/%s' % textset_id
#     if not os.path.exists(folder):
#         os.makedirs(folder)
# 
#     params_name = "-".join([key + '_' + str(params[key]) for key in params.keys()])
#     for c in ['[', ']', ',', '(', ')', '{', '}']:
#         params_name = params_name.replace(c, '')
#     return folder + '/%s-' % model_type + params_name.replace(' ', '_')


# Path: automlk/preprocessing.py
from abc import ABCMeta, abstractmethod
from sklearn.preprocessing import StandardScaler, MinMaxScaler, RobustScaler, MaxAbsScaler, Imputer, PolynomialFeatures, \
    LabelEncoder
from sklearn.decomposition import TruncatedSVD, FastICA, PCA
from sklearn.feature_selection import SelectFromModel
from sklearn.svm import LinearSVC, LinearSVR
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
from .spaces.process import *
from .utils.text_encoders import *
from .context import text_model_filename
    from gensim.models import Word2Vec, Doc2Vec
    from gensim.models.doc2vec import TaggedDocument
import numpy as np
import pickle
import pandas as pd
import category_encoders as ce

                encoder = model_doc2vec(X[col].values, self.transformer_params)
            self.feature_names.remove(col)
            self.feature_names += [col + '__' + str(i) for i in range(self.transformer_params['size'])]
            self.transformer.append((col, encoder))

    def transform(self, X):
        # transform X
        for col, encoder in self.transformer:
            T = pd.DataFrame(vector_doc2vec(encoder, X[col].values, self.params)).reset_index(drop=True)
            T.columns = [col + '__' + str(i) for i in range(self.transformer_params['size'])]
            X = pd.concat([X.reset_index(drop=True), T], axis=1)
            # remove col in X
            X.drop(col, axis=1, inplace=True)
        return X


def get_text_encoder(features, col, model_type, params):
    """
    get the encoder from a text column (col), with params

    :param features: list of features of the dataset
    :param col: column name
    :param model_type: model type (bow, w2v, d2v)
    :param params: params of the encoder (size, ...)
    :return: encoder or None
    """
    for f in features:
        if f['name'] == col:
            ref = f['text_ref']
            if ref != '':

                filename = text_model_filename(ref, model_type, params)