File size: 5,189 Bytes
5c2ce96
 
 
 
 
 
86bf0b9
5c2ce96
cbf0170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c2ce96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10127ea
5c2ce96
 
10127ea
 
5c2ce96
 
cbf0170
5c2ce96
 
 
 
 
 
 
 
 
 
 
cbf0170
5c2ce96
 
 
 
 
 
 
 
 
 
 
 
 
10127ea
911a721
 
 
 
 
e254d26
5c2ce96
ce254e3
509c6c9
ce254e3
 
 
297ff4d
911a721
69d34b7
5c2ce96
 
 
 
 
69d34b7
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
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
import tempfile

_CITATION = """\
@misc{letrascarnavalcadiz2023,
  author = {Romero Reyna, Iván and Franco Medinilla, Jesús Federico and Avecilla de la Herrán, Jesús Carlos},
  title = {letras-carnaval-cadiz},
  year = {2023},
  url = {https://huggingface.co/datasets/IES-Rafael-Alberti/letras-carnaval-cadiz}
}
"""

_DESCRIPTION = """\
This dataset is a comprehensive collection of lyrics from the Carnaval de Cádiz, a significant cultural heritage of the city of Cádiz, Spain. Despite its cultural importance, there has been a lack of a structured database for these lyrics, hindering research and public access to this cultural heritage. This dataset aims to address this gap.

The dataset was created by the Cádiz AI Learning Community, a branch of the non-profit association Spain AI, and was developed by Iván Romero Reyna and Jesús Federico Franco Medinilla, students of the Specialization Course in Artificial Intelligence and Big Data at IES Rafael Alberti during the 2022-2023 academic year. The project is supervised by Jesús Carlos Avecilla de la Herrán, a computational linguist.

Collaboration is encouraged, with individuals able to verify the different records of the dataset at letrascarnavalcadiz.com, ensuring the transcription of the lyrics and all data are correct. New lyrics can also be added to the dataset. Corrections and additions are not immediately reflected in the dataset but are updated periodically.

For more information or to report a problem, you can write to [email protected].
"""

# 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"),
        CadizCarnivalConfig(name="all", description="This part of my dataset covers both accurate and midaccurate data"),
    ]

    DEFAULT_CONFIG_NAME = "all"

    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"]})]
        else:  # Default is "all"
            # Load both JSON files and combine them
            with open(downloaded_files["accurate"], 'r') as f:
                data_accurate = json.load(f)
            with open(downloaded_files["midaccurate"], 'r') as f:
                data_midaccurate = json.load(f)
            data_all = data_accurate + data_midaccurate

            # Write the combined data to a temporary file
            with tempfile.NamedTemporaryFile(delete=False, mode='w') as temp_file:
                json.dump(data_all, temp_file)
                temp_filepath = temp_file.name

            return [SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": temp_filepath})]
    
    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