File size: 4,030 Bytes
3152459
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""TODO: Add a description here."""

import datasets
import gzip

logger = datasets.logging.get_logger(__name__)

# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
@InProceedings{huggingface:dataset,
title = {A great new dataset},
author={huggingface, Inc.
},
year={2020}
}
"""

_VERSION= "1.1.0"

# TODO: Add description of the dataset here
# You can copy an official description
_DESCRIPTION = """\
BSBasque dataset. The text is extracted from the following domains:

 https://www.berria.eus
 https://eu.wikipedia.org
 https://goiena.eus
 https://www.argia.eus
 https://goierri.hitza.eus

"""

# TODO: Add a link to an official homepage for the dataset here
_HOMEPAGE = "to.be.announced.eus"

# TODO: Add the licence for the dataset here if you can find it
_LICENSE = "CC BY-SA 4.0"

_BASE_DATA_URL_STR = (
    "https://ixa2.si.ehu.es/~ccpsoeta/bsbasque/"
)
_BASE_CHECKSUM_FILE_NAME = "bsbasque_sha256.txt"

class BsBasqueConfig(datasets.BuilderConfig):
    "BsBasque corpus."

    def __init__(self, **kwargs):
        """BuilderConfig for BsBasque.

        Args:
            **kwargs: Keyword arguments forwarded to super.
        """

        # Initialize the base class.
        name = "bsbasque"
        description = "BsBasque dataset"
        super(BsBasqueConfig, self).__init__(name=name, description=description, **kwargs)

        # Additional attributes
        self.base_data_url = _BASE_DATA_URL_STR


# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
class BSBasque(datasets.GeneratorBasedBuilder):
    """TODO: Short description of my dataset."""

    BUILDER_CONFIGS = [
        BsBasqueConfig(version=datasets.Version(_VERSION))
    ]
    BUILDER_CONFIG_CLASS = BsBasqueConfig

    def _info(self):
        # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features({"id": datasets.Value("int64"), "text": datasets.Value("string")}),
            supervised_keys=None,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        checksum_url = self.config.base_data_url + _BASE_CHECKSUM_FILE_NAME
        checksum_file = dl_manager.download(checksum_url)
        with open(checksum_file, encoding="utf-8") as f:
            data_filenames = [line.split("\t")[0] for line in f if line]
            data_urls = [self.config.base_data_url + data_filename for data_filename in data_filenames]
        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:
            logger.info("generating examples from = %s", filepath)
            with gzip.open(filepath, "rt") as f:
                for line in f:
                    feature = id_, {"id": id_, "text": "".join(line).rstrip()}
                    yield feature
                    id_ += 1