|
import os |
|
import zipfile |
|
import json |
|
import base64 |
|
|
|
import datasets |
|
|
|
try: |
|
import gitlab |
|
except ImportError: |
|
print("ERROR: To be able to retrieve this dataset you need to install the `python-gitlab` package") |
|
|
|
_CITATION = """\ |
|
@inproceedings{lecorve2022sparql2text, |
|
title={Coqar: Question rewriting on coqa}, |
|
author={Lecorv\'e, Gw\'enol\'e and Veyret, Morgan and Brabant, Quentin and Rojas-Barahona, Lina M.}, |
|
journal={Proceedings of the Conference of the Asia-Pacific Chapter of the Association for Computational Linguistics and the International Joint Conference on Natural Language Processing (AACL-IJCNLP)}, |
|
year={2022} |
|
} |
|
""" |
|
|
|
_HOMEPAGE = "" |
|
|
|
_URLS = { |
|
"train": "json/annotated_wd_data_train.json", |
|
"valid": "json/annotated_wd_data_valid.json", |
|
"test": "json/annotated_wd_data_test.json" |
|
} |
|
|
|
_DESCRIPTION = """\ |
|
SimpleQuestions-SPARQL2Text: Special version of SimpleQuestions with SPARQL queries formatted for the SPARQL-to-Text task |
|
""" |
|
|
|
|
|
class SimpleQuestions_SPARQL2Text(datasets.GeneratorBasedBuilder): |
|
""" |
|
SimpleQuestions-SPARQL2Text: Special version of SimpleQuestions with |
|
SPARQL queries formatted for the SPARQL-to-Text task |
|
""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
"original_nl_question": datasets.Value('string'), |
|
"recased_nl_question": datasets.Value('string'), |
|
"sparql_query": datasets.Value('string'), |
|
"verbalized_sparql_query": datasets.Value('string'), |
|
"nl_subject": datasets.Value('string'), |
|
"nl_property": datasets.Value('string'), |
|
"nl_object": datasets.Value('string'), |
|
"nl_answer": datasets.Value('string'), |
|
"rdf_subject": datasets.Value('string'), |
|
"rdf_property": datasets.Value('string'), |
|
"rdf_object": datasets.Value('string'), |
|
"rdf_answer": datasets.Value('string'), |
|
"rdf_target": datasets.Value('string') |
|
} |
|
), |
|
|
|
|
|
|
|
supervised_keys=("recased_nl_question", "verbalized_sparql_query"), |
|
|
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
paths = dl_manager.download_and_extract(_URLS) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"filepath": dl_manager.extract(paths['train']), |
|
"split": "train"} |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={"filepath": dl_manager.extract(paths['valid']), |
|
"split": "valid"} |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={"filepath": dl_manager.extract(paths['test']), |
|
"split": "test"} |
|
) |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
"""Yields examples.""" |
|
|
|
def transform_sample(original_sample): |
|
transformed_sample = { |
|
"original_nl_question": "", |
|
"recased_nl_question": "", |
|
"sparql_query": "", |
|
"verbalized_sparql_query": "", |
|
"nl_subject": "", |
|
"nl_property": "", |
|
"nl_object": "", |
|
"nl_answer": "", |
|
"rdf_subject": "", |
|
"rdf_property": "", |
|
"rdf_object": "", |
|
"rdf_answer": "", |
|
"rdf_target": "" |
|
} |
|
transformed_sample.update(original_sample) |
|
|
|
return transformed_sample |
|
|
|
|
|
with open(filepath,'r') as f: |
|
data = json.load(f) |
|
key = 0 |
|
for it in data: |
|
yield key, transform_sample(it) |
|
key += 1 |
|
|