from typing import List
from typing import Dict
from typing import Tuple


def generate_text_n_input_ontology_indices(
    text_fields: List[str], forte_data_fields_dict: Dict[str, str]
) -> Tuple[str, Dict[str, Tuple[int, int]]]:
    """
    Retrieve ontologies from data fields and concatenate them into text.
    Also, we generate the indices for these ontologies accordingly.

    Args:
        text_fields(List[str]): a list of ontology that needs to be
            concatenated into a input string.
        forte_data_fields_dict(Dict[str, str]): a dictionary with ontology names as keys and
            ontology strings as values.

    Returns:
        Tuple[str, Dict[str, Tuple[int, int]]]: a concatenated text and
            dictionary that keys are forte data entries and values are start
            and end indices of the data entries.
    """
    end = -1
    text = ""
    indices = {}  # a dictionary of (ontology_name: (start_index, end_index) )
    for i, input_onto in enumerate(text_fields):
        text += forte_data_fields_dict[input_onto]
        start = end + 1
        end = len(text)
        if i != len(text_fields) - 1:  # not last input ontology
            text += "\n"
        indices[text_fields[i]] = (start, end)

    return text, indices