File size: 2,246 Bytes
59104b9
 
 
 
 
 
 
 
 
 
2b28d41
35a993e
59104b9
 
 
 
 
 
 
 
 
 
 
 
35a993e
59104b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e63b916
59104b9
35a993e
59104b9
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# coding=utf-8

import collections
import gzip

import datasets


logger = datasets.logging.get_logger(__name__)

_FILES = ['10CGDFvfMddPmbkXiM4ntGZ75UyLAEX9N','1-uv2ALG5C7P02tAnOrRVoAyHsykWOTpg','10NUJo7Uf-Y1K1HS_Rj1wXPjEK6BsCnsR','1-xMQDKAssrgPs21plEI3wbn5sNmd5j_U','102iMMbfkInQwvIz8sLpz6AVgOhJFLcqo','10kZHAmyTpSWWVznqyWeSTYVJXq76cxmq','1-v2yDhV_f-eUSokNaNuy-iqLlXb2aQk-','108F-u0xgjGckwaprGidkP_PFUaiStEro','10taj31jPdDCBdla-2obITSn9LlllNC7D','111_rEBLm0V3yLZjBiAazUd25qDbwVE-O','10K1KGWjKeEOvvxjY5SHDBxOQNWWGCKmm','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("<END>", "\n").rstrip()}
                    yield feature
                    id_ += 1