def remove_nested_entities(matched_entities):
    """
    Find and remove matched entities that overlap with a larger one. I.e.: detect and remove entities contained
    in others. Ex. (Idris, 12, 17) is overlapped in (Faris Idris, 6, 17).
    :param matched_entities:
    :return: clean_matched_entities: without nested entities
    """
    clean_matched_entities = []
    len_matched_entities = len(matched_entities)
    for i in range(len_matched_entities):
        is_nested = False
        _, i_start_pos, i_end_pos = matched_entities[i]
        for j in range(len_matched_entities):
            _, j_start_pos, j_end_pos = matched_entities[j]
            if i_start_pos == j_start_pos and i_end_pos == j_end_pos:
                continue
            if i_start_pos >= j_start_pos and i_end_pos <= j_end_pos:
                # print(f"{matched_entities[i]} is nested :(")
                is_nested = True
                break
        if not is_nested:
            clean_matched_entities.append(matched_entities[i])

    return clean_matched_entities