import json


def get_grail_qa(split: str, path='../data/raw/grail_qa/') -> dict:
    """
    Get domains and questions from a `split` of grail_qa.
    """
    if split not in ('train', 'dev'):
        raise(ValueError("`split` must be one of 'train' or 'dev'"))

    path_prefix = path + 'grailqa_v1.0_'
    with open(path_prefix + f'{split}.json', 'rb') as f:
        data = json.load(f)

    domains, questions = [], []
    for entry in data:
        domains.append(';'.join(entry['domains']))  # entry['domains'] is an array
        questions.append(entry['question'])

    return {'domains': domains, 'questions': questions}