import logging
import json


def extract_english_corpus(json_str, verbose=False):
    """A helper function to extract English corpus from KPTimes dataset in json

    :param: json_str: the json string
    :param: verbose: bool, if logging the process of data processing

    :returns: the articles and keywords for each article
    :rtype: src (list of string), tgt (list of keyword list)
    """
    src = []
    tgt = []
    for idx in range(len(json_str)):
        if idx % 1000 == 0:
            if verbose:
                logging.info('processing idx: ', idx)
        data = json.loads(json_str[idx])
        article = data['abstract']
        keyword = data['keyword']
        keyword = keyword.split(';')
        src.append(article)
        tgt.append(keyword)
    return src, tgt