Upload letras-carnaval-cadiz.py
Browse files- letras-carnaval-cadiz.py +73 -0
letras-carnaval-cadiz.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datasets import DatasetBuilder, SplitGenerator, Split, Features, Value, Sequence, BuilderConfig, GeneratorBasedBuilder
|
2 |
+
import datasets
|
3 |
+
from datasets.utils.download_manager import DownloadManager
|
4 |
+
from typing import List, Any, Tuple
|
5 |
+
import json
|
6 |
+
import os
|
7 |
+
|
8 |
+
# Mapping for song_type and group_type
|
9 |
+
song_type_mapping = {
|
10 |
+
1: "presentación",
|
11 |
+
2: "pasodoble/tango",
|
12 |
+
3: "cuplé",
|
13 |
+
4: "estribillo",
|
14 |
+
5: "popurrí",
|
15 |
+
6: "cuarteta",
|
16 |
+
}
|
17 |
+
|
18 |
+
group_type_mapping = {
|
19 |
+
1: "coro",
|
20 |
+
2: "comparsa",
|
21 |
+
3: "chirigota",
|
22 |
+
4: "cuarteto",
|
23 |
+
}
|
24 |
+
|
25 |
+
class CadizCarnivalConfig(BuilderConfig):
|
26 |
+
def __init__(self, **kwargs):
|
27 |
+
super().__init__(version=datasets.Version("1.0.2"), **kwargs)
|
28 |
+
|
29 |
+
class CadizCarnivalDataset(GeneratorBasedBuilder):
|
30 |
+
VERSION = "1.0.0"
|
31 |
+
BUILDER_CONFIGS = [
|
32 |
+
CadizCarnivalConfig(name="accurate", description="This part of my dataset covers accurate data"),
|
33 |
+
CadizCarnivalConfig(name="midaccurate", description="This part of my dataset covers midaccurate data"),
|
34 |
+
]
|
35 |
+
|
36 |
+
def _info(self):
|
37 |
+
return datasets.DatasetInfo(
|
38 |
+
description="_DESCRIPTION",
|
39 |
+
features=datasets.Features({
|
40 |
+
"id": Value("string"),
|
41 |
+
"authors": Sequence(Value("string")),
|
42 |
+
"song_type": Value("string"),
|
43 |
+
"year": Value("string"),
|
44 |
+
"group": Value("string"),
|
45 |
+
"group_type": Value("string"),
|
46 |
+
"lyrics": Sequence(Value("string")),
|
47 |
+
}),
|
48 |
+
supervised_keys=None,
|
49 |
+
homepage="https://letrascarnavalcadiz.com/",
|
50 |
+
citation="_CITATION",
|
51 |
+
)
|
52 |
+
|
53 |
+
def _split_generators(self, dl_manager: DownloadManager) -> List[SplitGenerator]:
|
54 |
+
urls_to_download = {
|
55 |
+
"accurate": "https://huggingface.co/datasets/IES-Rafael-Alberti/letras-carnaval-cadiz/raw/main/data/accurate-00000-of-00001.json",
|
56 |
+
"midaccurate": "https://huggingface.co/datasets/IES-Rafael-Alberti/letras-carnaval-cadiz/raw/main/data/midaccurate-00000-of-00001.json"
|
57 |
+
}
|
58 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
59 |
+
|
60 |
+
if self.config.name == "accurate":
|
61 |
+
return [SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["accurate"]})]
|
62 |
+
elif self.config.name == "midaccurate":
|
63 |
+
return [SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["midaccurate"]})]
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
def _generate_examples(self, filepath: str):
|
68 |
+
with open(filepath, encoding="utf-8") as f:
|
69 |
+
data = json.load(f)
|
70 |
+
for item in data:
|
71 |
+
item["song_type"] = song_type_mapping.get(item["song_type"], "indefinido")
|
72 |
+
item["group_type"] = group_type_mapping.get(item["group_type"], "indefinido")
|
73 |
+
yield item["id"], item
|