letras-carnaval-cadiz / letras-carnaval-cadiz.py
davidlms's picture
Upload letras-carnaval-cadiz.py
21a91b1
raw
history blame
2.79 kB
from datasets import DatasetBuilder, SplitGenerator, Split, Features, Value, Sequence, BuilderConfig, GeneratorBasedBuilder
import datasets
from datasets.utils.download_manager import DownloadManager
from typing import List, Any, Tuple
import json
import os
# Mapping for song_type and group_type
song_type_mapping = {
1: "presentación",
2: "pasodoble/tango",
3: "cuplé",
4: "estribillo",
5: "popurrí",
6: "cuarteta",
}
group_type_mapping = {
1: "coro",
2: "comparsa",
3: "chirigota",
4: "cuarteto",
}
class CadizCarnivalConfig(BuilderConfig):
def __init__(self, **kwargs):
super().__init__(version=datasets.Version("1.0.2"), **kwargs)
class CadizCarnivalDataset(GeneratorBasedBuilder):
VERSION = "1.0.0"
BUILDER_CONFIGS = [
CadizCarnivalConfig(name="accurate", description="This part of my dataset covers accurate data"),
CadizCarnivalConfig(name="midaccurate", description="This part of my dataset covers midaccurate data"),
]
def _info(self):
return datasets.DatasetInfo(
description="_DESCRIPTION",
features=datasets.Features({
"id": Value("string"),
"authors": Sequence(Value("string")),
"song_type": Value("string"),
"year": Value("string"),
"group": Value("string"),
"group_type": Value("string"),
"lyrics": Sequence(Value("string")),
}),
supervised_keys=None,
homepage="https://letrascarnavalcadiz.com/",
citation="_CITATION",
)
def _split_generators(self, dl_manager: DownloadManager) -> List[SplitGenerator]:
urls_to_download = {
"accurate": "https://huggingface.co/datasets/IES-Rafael-Alberti/letras-carnaval-cadiz/raw/main/data/accurate-00000-of-00001.json",
"midaccurate": "https://huggingface.co/datasets/IES-Rafael-Alberti/letras-carnaval-cadiz/raw/main/data/midaccurate-00000-of-00001.json"
}
downloaded_files = dl_manager.download_and_extract(urls_to_download)
if self.config.name == "accurate":
return [SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["accurate"]})]
elif self.config.name == "midaccurate":
return [SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["midaccurate"]})]
def _generate_examples(self, filepath: str):
with open(filepath, encoding="utf-8") as f:
data = json.load(f)
for item in data:
item["song_type"] = song_type_mapping.get(item["song_type"], "indefinido")
item["group_type"] = group_type_mapping.get(item["group_type"], "indefinido")
yield item["id"], item