Get a training, validation and a testset as well as a dictionary that maps
    each formula_id to an index (0...nr_of_formulas - 1).

    Parameters
    ----------
    path_to_data :
        A pickle file that contains a list of datasets.

    Returns
    -------
    tuple
        0: list
            The training_set contains recordings.
        1: list
            The validation_set contains recordings.
        2: list
            The test_set contains recordings.
        3: dict
            The formula_id2index maps write-math.com formula ids to
            an index which begins at 0.
        4: list
            The preprocessing_queue contains objects which encapsulate
            algorithms for preprocessing.
        5: dict
            The index2latex maps the index of the neural network to the latex
            command.

def get_sets(path_to_data):
    """
    Get a training, validation and a testset as well as a dictionary that maps
    each formula_id to an index (0...nr_of_formulas - 1).

    Parameters
    ----------
    path_to_data :
        A pickle file that contains a list of datasets.

    Returns
    -------
    tuple
        0: list
            The training_set contains recordings.
        1: list
            The validation_set contains recordings.
        2: list
            The test_set contains recordings.
        3: dict
            The formula_id2index maps write-math.com formula ids to
            an index which begins at 0.
        4: list
            The preprocessing_queue contains objects which encapsulate
            algorithms for preprocessing.
        5: dict
            The index2latex maps the index of the neural network to the latex
            command.
    """
    loaded = pickle.load(open(path_to_data, 'rb'))
    datasets = loaded['handwriting_datasets']

    training_set, validation_set, test_set = [], [], []

    dataset_by_formula_id = {}
    formula_id2index = {}
    index2latex = {}

    # Group data in dataset_by_formula_id so that 10% can be used for the
    # validation set
    for i, dataset in enumerate(datasets):
        if dataset['formula_id'] in dataset_by_formula_id:
            dataset_by_formula_id[dataset['formula_id']].append(dataset)
        else:
            dataset_by_formula_id[dataset['formula_id']] = [dataset]
        utils.print_status(len(datasets), i)
    print("")

    # Create the test-, validation- and training set
    print("Create the test-, validation- and training set")
    for formula_id, dataset in dataset_by_formula_id.items():
        tmp = dataset[0]['handwriting'].formula_in_latex
        index2latex[len(formula_id2index)] = tmp
        formula_id2index[formula_id] = len(formula_id2index)
        i = 0
        for raw_data in dataset:
            if raw_data['is_in_testset']:
                test_set.append(raw_data)
            else:
                if i % 10 == 0:
                    validation_set.append(raw_data)
                else:
                    training_set.append(raw_data)
                i = (i + 1) % 10
    if 'preprocessing_queue' in loaded:
        preprocessing_queue = loaded['preprocessing_queue']
    else:
        preprocessing_queue = []
    return (training_set, validation_set, test_set, formula_id2index,
            preprocessing_queue, index2latex)