# 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/spaces/process.py
# NO_PARAMS = {}


import pickle
from .monitor import *
from .context import text_model_filename
from .textset import *
from .utils.text_encoders import *
from .spaces.process import space_textset_bow, space_textset_w2v, space_textset_d2v

    #if textset.status != 'created':
    #    raise ValueError('textset status must be created')

    return pickle.load(open(get_data_folder() + '/texts/w2v_%d_%d.pkl' % (textset_id, size), 'rb'))


def worker_text_loop():
    """
    periodically pool the receiver queue for a search job

    :return:
    """
    while True:
        heart_beep('worker_text', '')
        # check the list of datasets
        for ts in get_textset_list():
            if ts.status != 'completed':
                heart_beep('worker_text', {'textset_id': ts.textset_id, 'textset_name': ts.name})
                log.info('searching textset %s' % ts.textset_id)

                # read textset
                textset = get_textset(ts.textset_id)
                set_key_store('textset:%s:status' % ts.textset_id, 'searching')

                # import text
                with open(textset.filename, 'r') as f:
                    text = f.readlines()

                # calculate models

# 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/spaces/process.py
# NO_PARAMS = {}


# Path: automlk/worker_text.py
import pickle
from .monitor import *
from .context import text_model_filename
from .textset import *
from .utils.text_encoders import *
from .spaces.process import space_textset_bow, space_textset_w2v, space_textset_d2v


    #if textset.status != 'created':
    #    raise ValueError('textset status must be created')

    return pickle.load(open(get_data_folder() + '/texts/w2v_%d_%d.pkl' % (textset_id, size), 'rb'))


def worker_text_loop():
    """
    periodically pool the receiver queue for a search job

    :return:
    """
    while True:
        heart_beep('worker_text', '')
        # check the list of datasets
        for ts in get_textset_list():
            if ts.status != 'completed':
                heart_beep('worker_text', {'textset_id': ts.textset_id, 'textset_name': ts.name})
                log.info('searching textset %s' % ts.textset_id)

                # read textset
                textset = get_textset(ts.textset_id)
                set_key_store('textset:%s:status' % ts.textset_id, 'searching')

                # import text
                with open(textset.filename, 'r') as f:
                    text = f.readlines()

                # calculate models

                for conf in space_textset_bow: