def detect_new_entities()

in source/lambda_handlers/03-HumanReviewCompleted.py [0:0]


def detect_new_entities(custom_entities_content, new_entity_text, new_entity_type):
    # Loop over each entity to check for its existence in the ones
    # marked by the human reviewer
    line_count = 0

    existing_entity_text_list = []
    existing_entity_type_list = []

    for entity in custom_entities_content:
        row = str(entity).replace("b'", "").replace("'", "").split(',')
        if line_count != 0 and len(row) == 2:
            if row[0] in new_entity_text:
                index_to_delete = new_entity_text.index(row[0])
                new_entity_text.pop(index_to_delete)
                new_entity_type.pop(index_to_delete)
            existing_entity_text_list.append(row[0])
            existing_entity_type_list.append(row[1])
        line_count += 1

    cleaned_values = {}
    cleaned_values['entity_text'] = existing_entity_text_list + new_entity_text
    cleaned_values['entity_type'] = existing_entity_type_list + new_entity_type
    if len(cleaned_values['entity_text']) == (len(custom_entities_content) - 2):
        cleaned_values['retraining_required'] = False
    else:
        cleaned_values['retraining_required'] = True

    return cleaned_values