# coding=utf-8 import collections import gzip import datasets logger = datasets.logging.get_logger(__name__) _FILES = ['10YelrSn-sjGptw2ns5uZUEMSa58VNmF1'] _BASE_DATA_URL = "https://drive.google.com/file/d/" class BrwacCleanConfig(datasets.BuilderConfig): """BRWAC-clean corpus.""" def __init__(self, **kwargs): # Initialize the base class. name = "brwac-clean" description = "brwac-clean dataset" super(BrwacCleanConfig, self).__init__(name=name, description=description, **kwargs) # Additional attributes self.base_data_url = _BASE_DATA_URL class BrwacClean(datasets.GeneratorBasedBuilder): """BRWAC corpus.""" BUILDER_CONFIGS = [ BrwacCleanConfig( version=datasets.Version("1.0.0"), ) ] BUILDER_CONFIG_CLASS = BrwacCleanConfig def _info(self): return datasets.DatasetInfo( features=datasets.Features({"id": datasets.Value("int64"), "text": datasets.Value("string")}), supervised_keys=None, ) def _split_generators(self, dl_manager): data_urls = [self.config.base_data_url + data_filename for data_filename in _FILES] downloaded_files = dl_manager.download(data_urls) return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files}), ] def _generate_examples(self, filepaths): """This function returns the examples in the raw (text) form by iterating on all the files.""" id_ = 0 for filepath in filepaths: with gzip.open(open(filepath, "rb"), "rt", encoding="utf-8") as f: for line in f: feature = id_, {"id": id_, "text": line.replace("", "\n").rstrip()} yield feature id_ += 1