from typing import List
from typing import Dict
import json
import logging


def _load_data(data_file: str) -> List[Dict]:
    """
    Method load data from JSONL file and drops records with noise, such as:
    1. value is empty.
    2. value is not contained in the sentence

    :param data_file: path to JSON file
    :return: List[Dict]
    """
    results = []
    with open(data_file, "r") as in_fp:
        for json_line in in_fp:
            try:
                utterance_json = json.loads(json_line.strip())
                value = utterance_json["value"]
                parameter = utterance_json["parameter"]
                utterance = utterance_json["utterance"]
                if not value:
                    logging.warning(f"value is empty in: {utterance_json}")
                    continue
                if not parameter:
                    logging.warning(f"parameter is empty in: {utterance_json}")
                    continue
                if value not in utterance:
                    logging.warning(f"value: '{value}' not in utterance: {utterance}")
                    continue
                results.append(utterance_json)
            except json.decoder.JSONDecodeError:
                logging.warning(f"line: {json_line.strip()} has a broken json schema")
    return results