# 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. | |
"""Catalan Textual Corpus.""" | |
import csv | |
import json | |
import os | |
import datasets | |
# 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} | |
} | |
""" | |
# TODO: Add description of the dataset here | |
# You can copy an official description | |
_DESCRIPTION = """\ | |
The Catalan Textual Corpus is a 1760-million-token web corpus of Catalan built from several sources: existing corpus such as DOGC, CaWac (non-dedup version), Oscar (unshuffled version), Open Subtitles, Catalan Wikipedia; and three brand new crawlings: the Catalan General Crawling, obtained by crawling the 500 most popular .cat and .ad domains; the Catalan Government Crawling, obtained by crawling the .gencat domain and subdomains, belonging to the Catalan Government; and the ACN corpus with 220k news items from March 2015 until October 2020, crawled from the Catalan News Agency. | |
It consists of 1.758.388.896 tokens, 73.172.152 sentences and 12.556.365 documents. Documents are separated by single new lines. These boundaries have been preserved as long as the license allowed it. | |
""" | |
_HOMEPAGE = "https://zenodo.org/record/4519349#.YapK5roo9PY" | |
_LICENSE = "Creative Commons Attribution-ShareAlike 4.0 International License" | |
_URL = "https://zenodo.org/record/4519349/files/catalan_textual_corpus.zip?download=1" | |
class CatalanTextualCorpus(datasets.GeneratorBasedBuilder): | |
"""Catalan Textual Corpus.""" | |
VERSION = datasets.Version("1.0.0") | |
def _info(self): | |
# # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset | |
# if self.config.name == "first_domain": # This is the name of the configuration selected in BUILDER_CONFIGS above | |
# features = datasets.Features( | |
# { | |
# "sentence": datasets.Value("string"), | |
# "option1": datasets.Value("string"), | |
# "answer": datasets.Value("string") | |
# # These are the features of your dataset like images, labels ... | |
# } | |
# ) | |
# else: # This is an example to show how to have different features for "first_domain" and "second_domain" | |
# features = datasets.Features( | |
# { | |
# "sentence": datasets.Value("string"), | |
# "option2": datasets.Value("string"), | |
# "second_domain_answer": datasets.Value("string") | |
# # These are the features of your dataset like images, labels ... | |
# } | |
# ) | |
return datasets.DatasetInfo( | |
description=_DESCRIPTION, | |
features=None, | |
# If there's a common (input, target) tuple from the features, | |
# specify them here. They'll be used if as_supervised=True in | |
# builder.as_dataset. | |
supervised_keys=None, | |
homepage=_HOMEPAGE, | |
license=_LICENSE, | |
citation=_CITATION, | |
) | |
def _split_generators(self, dl_manager): | |
data_dir = dl_manager.download_and_extract(_URL) | |
return [ | |
datasets.SplitGenerator( | |
name=datasets.Split.TRAIN, | |
# These kwargs will be passed to _generate_examples | |
gen_kwargs={ | |
"filepath": os.path.join(data_dir, "corpus", "catalan_textual_corpus.txt"), | |
# "split": "train", | |
}, | |
), | |
# datasets.SplitGenerator( | |
# name=datasets.Split.TEST, | |
# # These kwargs will be passed to _generate_examples | |
# gen_kwargs={ | |
# "filepath": os.path.join(data_dir, "test.jsonl"), | |
# "split": "test" | |
# }, | |
# ), | |
# datasets.SplitGenerator( | |
# name=datasets.Split.VALIDATION, | |
# # These kwargs will be passed to _generate_examples | |
# gen_kwargs={ | |
# "filepath": os.path.join(data_dir, "dev.jsonl"), | |
# "split": "dev", | |
# }, | |
# ), | |
] | |
def _generate_examples(self, filepath): | |
with open(filepath, encoding="utf-8") as f: | |
text = "" | |
for id_, line in enumerate(f): | |
if line == "\n": | |
yield id_, {"text": text} | |
text = "" | |
else: | |
text += line | |