File size: 15,092 Bytes
668d32e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b591167
668d32e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Igbo Monolingual Dataset"""


import json
import os

import datasets


_CITATION = """\
@misc{ezeani2020igboenglish,
title={Igbo-English Machine Translation: An Evaluation Benchmark},
author={Ignatius Ezeani and Paul Rayson and Ikechukwu Onyenwe and Chinedu Uchechukwu and Mark Hepple},
year={2020},
eprint={2004.00648},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
"""

_DESCRIPTION = """\
A dataset is a collection of Monolingual Igbo sentences.
"""

_HOMEPAGE = "https://github.com/IgnatiusEzeani/IGBONLP/tree/master/ig_monoling"

_URL = "https://github.com/IgnatiusEzeani/IGBONLP/raw/master/ig_monoling/json.zip"


class IgboMonolingual(datasets.GeneratorBasedBuilder):
    """collection of Monolingual Igbo sentences from different sources"""

    VERSION = datasets.Version("1.1.0")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name="eze_goes_to_school",
            version=VERSION,
            description="Igbo sentences from Master's Thesis; UZOALOR, JOY UCHE",
        ),
        datasets.BuilderConfig(
            name="bbc-igbo", version=VERSION, description="Igbo sentences from https://www.bbc.com/igbo/"
        ),
        datasets.BuilderConfig(
            name="igbo-radio", version=VERSION, description="Igbo sentences from https://www.igboradio.com"
        ),
        datasets.BuilderConfig(
            name="jw-ot-igbo", version=VERSION, description="Igbo sentences from 929 pages of 39 books"
        ),
        datasets.BuilderConfig(
            name="jw-nt-igbo", version=VERSION, description="Igbo sentences from 260 pages of 27 books"
        ),
        datasets.BuilderConfig(
            name="jw-books", version=VERSION, description="Igbo sentences from 2204 pages of 48 books "
        ),
        datasets.BuilderConfig(
            name="jw-teta", version=VERSION, description="Igbo sentences from 392 pages of 37 magazines"
        ),
        datasets.BuilderConfig(
            name="jw-ulo_nche", version=VERSION, description="Igbo sentences from 594 pages of 55 magazines"
        ),
        datasets.BuilderConfig(
            name="jw-ulo_nche_naamu", version=VERSION, description="Igbo sentences from 870 pages of 88 magazines"
        ),
    ]

    def _info(self):
        if self.config.name == "eze_goes_to_school":
            features = datasets.Features(
                {
                    "format": datasets.Value("string"),
                    "title": datasets.Value("string"),
                    "chapters": datasets.Sequence(
                        {"title": datasets.Value("string"), "content": datasets.Value("string")}
                    ),
                }
            )
        elif self.config.name == "bbc-igbo":
            features = datasets.Features(
                {
                    "source": datasets.Value("string"),
                    "title": datasets.Value("string"),
                    "description": datasets.Value("string"),
                    "date": datasets.Value("string"),
                    "headline": datasets.Value("string"),
                    "content": datasets.Value("string"),
                    "tags": datasets.Sequence(datasets.Value("string")),
                }
            )
        elif self.config.name == "igbo-radio":
            features = datasets.Features(
                {
                    "source": datasets.Value("string"),
                    "headline": datasets.Value("string"),
                    "author": datasets.Value("string"),
                    "date": datasets.Value("string"),
                    "description": datasets.Value("string"),
                    "content": datasets.Value("string"),
                }
            )
        elif self.config.name == "jw-ot-igbo":
            features = datasets.Features(
                {
                    "format": datasets.Value("string"),
                    "title": datasets.Value("string"),
                    "chapters": datasets.Sequence(
                        {"title": datasets.Value("string"), "content": datasets.Value("string")}
                    ),
                }
            )
        elif self.config.name == "jw-nt-igbo":
            features = datasets.Features(
                {
                    "format": datasets.Value("string"),
                    "title": datasets.Value("string"),
                    "chapters": datasets.Sequence(
                        {"title": datasets.Value("string"), "content": datasets.Value("string")}
                    ),
                }
            )
        elif self.config.name == "jw-books":
            features = datasets.Features(
                {
                    "title": datasets.Value("string"),
                    "content": datasets.Value("string"),
                    "format": datasets.Value("string"),
                    "date": datasets.Value("string"),
                }
            )
        elif self.config.name == "jw-teta":
            features = datasets.Features(
                {
                    "title": datasets.Value("string"),
                    "content": datasets.Value("string"),
                    "format": datasets.Value("string"),
                    "date": datasets.Value("string"),
                }
            )
        elif self.config.name == "jw-ulo_nche":
            features = datasets.Features(
                {
                    "title": datasets.Value("string"),
                    "content": datasets.Value("string"),
                    "format": datasets.Value("string"),
                    "date": datasets.Value("string"),
                }
            )
        elif self.config.name == "jw-ulo_nche_naamu":
            features = datasets.Features(
                {
                    "title": datasets.Value("string"),
                    "content": datasets.Value("string"),
                    "format": datasets.Value("string"),
                    "date": datasets.Value("string"),
                }
            )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            supervised_keys=None,
            homepage=_HOMEPAGE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        data_dir = dl_manager.download_and_extract(_URL)
        if self.config.name == "eze_goes_to_school":
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={
                        "filepath": os.path.join(data_dir, "eze_goes_to_school.json"),
                        "split": "train",
                    },
                ),
            ]
        elif self.config.name == "bbc-igbo":
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={
                        "filepath": os.path.join(data_dir, "bbc-igbo.json"),
                        "split": "train",
                    },
                ),
            ]
        elif self.config.name == "igbo-radio":
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={
                        "filepath": os.path.join(data_dir, "igbo-radio.json"),
                        "split": "train",
                    },
                ),
            ]
        elif self.config.name == "jw-ot-igbo":
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={
                        "filepath": os.path.join(data_dir, "jw-ot-igbo.json"),
                        "split": "train",
                    },
                ),
            ]
        elif self.config.name == "jw-nt-igbo":
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={
                        "filepath": os.path.join(data_dir, "jw-nt-igbo.json"),
                        "split": "train",
                    },
                ),
            ]
        elif self.config.name == "jw-books":
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={
                        "filepath": os.path.join(data_dir, "jw-books.json"),
                        "split": "train",
                    },
                ),
            ]
        elif self.config.name == "jw-teta":
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={
                        "filepath": os.path.join(data_dir, "jw-teta.json"),
                        "split": "train",
                    },
                ),
            ]
        elif self.config.name == "jw-ulo_nche":
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={
                        "filepath": os.path.join(data_dir, "jw-ulo_nche.json"),
                        "split": "train",
                    },
                ),
            ]
        elif self.config.name == "jw-ulo_nche_naamu":
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={
                        "filepath": os.path.join(data_dir, "jw-ulo_nche_naamu.json"),
                        "split": "train",
                    },
                ),
            ]

    def _generate_examples(self, filepath, split):
        """Yields examples."""
        if self.config.name == "eze_goes_to_school":
            with open(filepath, "r", encoding="utf-8") as f:
                json_data = json.load(f)
                for id_, data in enumerate(json_data):
                    yield id_, {
                        "format": data["format"],
                        "title": data["title"],
                        "chapters": data["chapters"],
                    }
        elif self.config.name == "bbc-igbo":
            with open(filepath, "r", encoding="utf-8") as f:
                json_data = json.load(f)
                for id_, data in enumerate(json_data):
                    yield id_, {
                        "source": data["source"] if "source" in data.keys() else "",
                        "title": data["title"] if "title" in data.keys() else "",
                        "description": data["description"] if "description" in data.keys() else "",
                        "date": data["date"] if "date" in data.keys() else "",
                        "headline": data["headline"] if "headline" in data.keys() else "",
                        "content": data["content"] if "content" in data.keys() else "",
                        "tags": data["tags"] if "tags" in data.keys() else [],
                    }
        elif self.config.name == "igbo-radio":
            with open(filepath, "r", encoding="utf-8") as f:
                json_data = json.load(f)
                for id_, data in enumerate(json_data):
                    yield id_, {
                        "source": data["source"],
                        "headline": data["headline"],
                        "author": data["author"],
                        "date": data["date"],
                        "description": data["description"] if "description" in data.keys() else "",
                        "content": data["content"] if "content" in data.keys() else "",
                    }
        elif self.config.name == "jw-ot-igbo":
            with open(filepath, "r", encoding="utf-8") as f:
                json_data = json.load(f)
                for id_, data in enumerate(json_data):
                    yield id_, {
                        "format": data["format"],
                        "title": data["title"],
                        "chapters": data["chapters"],
                    }
        elif self.config.name == "jw-nt-igbo":
            with open(filepath, "r", encoding="utf-8") as f:
                json_data = json.load(f)
                for id_, data in enumerate(json_data):
                    yield id_, {
                        "format": data["format"],
                        "title": data["title"],
                        "chapters": data["chapters"],
                    }
        elif self.config.name == "jw-books":
            with open(filepath, "r", encoding="utf-8") as f:
                json_data = json.load(f)
                for id_, data in enumerate(json_data):
                    yield id_, {
                        "title": data["title"],
                        "content": data["content"],
                        "format": data["format"],
                        "date": data["date"] if "date" in data.keys() else "",
                    }
        elif self.config.name == "jw-teta":
            with open(filepath, "r", encoding="utf-8") as f:
                json_data = json.load(f)
                for id_, data in enumerate(json_data):
                    yield id_, {
                        "title": data["title"],
                        "content": data["content"],
                        "format": data["format"],
                        "date": data["date"] if "date" in data.keys() else "",
                    }
        elif self.config.name == "jw-ulo_nche":
            with open(filepath, "r", encoding="utf-8") as f:
                json_data = json.load(f)
                for id_, data in enumerate(json_data):
                    yield id_, {
                        "title": data["title"],
                        "content": data["content"],
                        "format": data["format"],
                        "date": data["date"] if "date" in data.keys() else "",
                    }
        elif self.config.name == "jw-ulo_nche_naamu":
            with open(filepath, "r", encoding="utf-8") as f:
                json_data = json.load(f)
                for id_, data in enumerate(json_data):
                    yield id_, {
                        "title": data["title"],
                        "content": data["content"],
                        "format": data["format"],
                        "date": data["date"] if "date" in data.keys() else "",
                    }