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