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=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
"""Multilingual Bibles"""
|
16 |
+
import csv
|
17 |
+
|
18 |
+
import datasets
|
19 |
+
|
20 |
+
|
21 |
+
_CITATION = """
|
22 |
+
@InProceedings{--,
|
23 |
+
author = {---},
|
24 |
+
title = {---},
|
25 |
+
booktitle = {---},
|
26 |
+
year = 2021,
|
27 |
+
address = "---"
|
28 |
+
}
|
29 |
+
"""
|
30 |
+
|
31 |
+
_DESCRIPTION = """\
|
32 |
+
Multilingual Bibles
|
33 |
+
"""
|
34 |
+
|
35 |
+
|
36 |
+
_HOMEPAGE = "https://github.com/versae/bibles/"
|
37 |
+
|
38 |
+
BIBLES_BASE_URI = "https://huggingface.co/datasets/versae/bibles/resolve/main"
|
39 |
+
BIBLES = {
|
40 |
+
"validation": lambda config: f"{BIBLES_BASE_URI}/{config}_validation.csv",
|
41 |
+
"test": lambda config: f"{BIBLES_BASE_URI}/{config}_test.csv",
|
42 |
+
"train": lambda config: f"{BIBLES_BASE_URI}/{config}_train.csv"
|
43 |
+
}
|
44 |
+
|
45 |
+
|
46 |
+
class BiblesConfig(datasets.BuilderConfig):
|
47 |
+
"""BuilderConfig for NorNE."""
|
48 |
+
|
49 |
+
def __init__(self, **kwargs):
|
50 |
+
"""BuilderConfig for Bibles.
|
51 |
+
Args:
|
52 |
+
**kwargs: keyword arguments forwarded to super.
|
53 |
+
"""
|
54 |
+
super(BiblesConfig, self).__init__(**kwargs)
|
55 |
+
|
56 |
+
|
57 |
+
class Bibles(datasets.GeneratorBasedBuilder):
|
58 |
+
"""Bibles"""
|
59 |
+
|
60 |
+
BUILDER_CONFIGS = [
|
61 |
+
BiblesConfig(name="testament", version=datasets.Version("1.0.0"), description="Bibles testament dataset (full set)"),
|
62 |
+
BiblesConfig(name="genre", version=datasets.Version("1.0.0"), description="Bibles genre dataset (full set)"),
|
63 |
+
BiblesConfig(name="division", version=datasets.Version("1.0.0"), description="Bibles division dataset (full set)"),
|
64 |
+
]
|
65 |
+
|
66 |
+
def _info(self):
|
67 |
+
if self.config.name == "division":
|
68 |
+
labels = [
|
69 |
+
'Gospel',
|
70 |
+
'Historical',
|
71 |
+
'Letters',
|
72 |
+
'Pentateuch',
|
73 |
+
'Prophetic',
|
74 |
+
'Revelation',
|
75 |
+
'Wisdom'
|
76 |
+
]
|
77 |
+
languages = [
|
78 |
+
'ALB',
|
79 |
+
'ARA',
|
80 |
+
'AZB',
|
81 |
+
'BEL',
|
82 |
+
'BUL',
|
83 |
+
'CEB',
|
84 |
+
'CHI',
|
85 |
+
'CZE',
|
86 |
+
'DAN',
|
87 |
+
'ENG',
|
88 |
+
'ESP',
|
89 |
+
'FIN',
|
90 |
+
'FRE',
|
91 |
+
'GER',
|
92 |
+
'GRC',
|
93 |
+
'HAT',
|
94 |
+
'HEB',
|
95 |
+
'HIN',
|
96 |
+
'HUN',
|
97 |
+
'ITA',
|
98 |
+
'KOR',
|
99 |
+
'LAT',
|
100 |
+
'MAR',
|
101 |
+
'NL_',
|
102 |
+
'NOR',
|
103 |
+
'POR',
|
104 |
+
'RUM',
|
105 |
+
'RUS',
|
106 |
+
'SCR',
|
107 |
+
'SPA',
|
108 |
+
'SWE',
|
109 |
+
'TAM',
|
110 |
+
'TGL',
|
111 |
+
'THA',
|
112 |
+
'TUR',
|
113 |
+
'VIE',
|
114 |
+
'XKL',
|
115 |
+
]
|
116 |
+
elif self.config.name == "genre":
|
117 |
+
labels = [
|
118 |
+
'apocalyptic',
|
119 |
+
'gospel',
|
120 |
+
'historical',
|
121 |
+
'law',
|
122 |
+
'letter',
|
123 |
+
'lyric',
|
124 |
+
'prophecy',
|
125 |
+
'wisdom'
|
126 |
+
]
|
127 |
+
languages = [
|
128 |
+
'ALB',
|
129 |
+
'ARA',
|
130 |
+
'AZB',
|
131 |
+
'BEL',
|
132 |
+
'BUL',
|
133 |
+
'CEB',
|
134 |
+
'CHI',
|
135 |
+
'CZE',
|
136 |
+
'DAN',
|
137 |
+
'ENG',
|
138 |
+
'ESP',
|
139 |
+
'FIN',
|
140 |
+
'FRE',
|
141 |
+
'GER',
|
142 |
+
'GRC',
|
143 |
+
'HAT',
|
144 |
+
'HEB',
|
145 |
+
'HIN',
|
146 |
+
'HUN',
|
147 |
+
'ITA',
|
148 |
+
'KOR',
|
149 |
+
'LAT',
|
150 |
+
'MAR',
|
151 |
+
'NL_',
|
152 |
+
'NOR',
|
153 |
+
'POR',
|
154 |
+
'RUM',
|
155 |
+
'RUS',
|
156 |
+
'SCR',
|
157 |
+
'SPA',
|
158 |
+
'SWE',
|
159 |
+
'TAM',
|
160 |
+
'TGL',
|
161 |
+
'THA',
|
162 |
+
'TUR',
|
163 |
+
'VIE',
|
164 |
+
'XKL',
|
165 |
+
]
|
166 |
+
else: # self.config.name == "testament":
|
167 |
+
labels = ["new", "old"]
|
168 |
+
languages = [
|
169 |
+
'ALB',
|
170 |
+
'ARA',
|
171 |
+
'AZB',
|
172 |
+
'BEL',
|
173 |
+
'BUL',
|
174 |
+
'CEB',
|
175 |
+
'CHA',
|
176 |
+
'CHI',
|
177 |
+
'CZE',
|
178 |
+
'DAN',
|
179 |
+
'ENG',
|
180 |
+
'ESP',
|
181 |
+
'FIN',
|
182 |
+
'FRE',
|
183 |
+
'GER',
|
184 |
+
'GRC',
|
185 |
+
'HAT',
|
186 |
+
'HEB',
|
187 |
+
'HIN',
|
188 |
+
'HUN',
|
189 |
+
'ITA',
|
190 |
+
'KOR',
|
191 |
+
'LAT',
|
192 |
+
'MAR',
|
193 |
+
'NDS',
|
194 |
+
'NL_',
|
195 |
+
'NOR',
|
196 |
+
'PON',
|
197 |
+
'POR',
|
198 |
+
'RUM',
|
199 |
+
'RUS',
|
200 |
+
'SCR',
|
201 |
+
'SPA',
|
202 |
+
'SWE',
|
203 |
+
'TAM',
|
204 |
+
'TGL',
|
205 |
+
'THA',
|
206 |
+
'TUR',
|
207 |
+
'VIE',
|
208 |
+
'XKL',
|
209 |
+
]
|
210 |
+
self.labels = labels
|
211 |
+
self.languages = languages
|
212 |
+
return datasets.DatasetInfo(
|
213 |
+
description=_DESCRIPTION,
|
214 |
+
features=datasets.Features(
|
215 |
+
{
|
216 |
+
"text": datasets.Value("string"),
|
217 |
+
"label": datasets.ClassLabel(names=labels),
|
218 |
+
"language": datasets.ClassLabel(names=languages),
|
219 |
+
}
|
220 |
+
),
|
221 |
+
supervised_keys=None,
|
222 |
+
homepage=_HOMEPAGE,
|
223 |
+
citation=_CITATION,
|
224 |
+
)
|
225 |
+
|
226 |
+
def _split_generators(self, dl_manager):
|
227 |
+
URLS = {key: BIBLES[key](self.config.name) for key in BIBLES.keys()}
|
228 |
+
downloaded_files = dl_manager.download(URLS)
|
229 |
+
return [
|
230 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
231 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["validation"]}),
|
232 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
233 |
+
]
|
234 |
+
|
235 |
+
def _generate_examples(self, filepath):
|
236 |
+
with open(filepath, encoding="utf-8") as csv_file:
|
237 |
+
csv_reader = csv.reader(csv_file, delimiter=",")
|
238 |
+
for idx, (text, label, language) in enumerate(csv_reader):
|
239 |
+
yield int(idx), {
|
240 |
+
"text": text,
|
241 |
+
"label": self.label.index(label),
|
242 |
+
"language": self.language.index(language),
|
243 |
+
}
|