from typing import List
import json


def load_train_data(train_data_files: str) -> List:
    """Load jsonl train data as a list, ready to be ingested by spacy model.

    Args:
        train_data_local_path (str): Path of files to load.

    Returns:
        List: Tuple of texts and dict of entities to be used for training.
    """
    train_data = []
    for data_file in train_data_files:
        with open(data_file, "r") as f:
            for json_str in list(f):
                train_data_dict = json.loads(json_str)
                train_text = train_data_dict["text"]
                train_entities = {
                    "entities": [
                        tuple(entity_elt) for entity_elt in train_data_dict["entities"]
                    ]
                }
                formatted_train_line = (train_text, train_entities)
                train_data.append(formatted_train_line)
    return train_data