bsbasque / bsbasque.py
asoroa's picture
Upload main script
3152459
# 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