Datasets:
updated dafand.py
#1
by kinged0043 - opened
dafand.py
CHANGED
|
@@ -4,55 +4,52 @@ import json
|
|
| 4 |
logger = datasets.logging.get_logger(__name__)
|
| 5 |
|
| 6 |
_DESCRIPTION = """
|
| 7 |
-
|
| 8 |
"""
|
| 9 |
|
| 10 |
-
_URL = "https://raw
|
| 11 |
-
_TRAINING_FILE = "train.json"
|
| 12 |
|
| 13 |
-
class
|
| 14 |
-
"""
|
| 15 |
def __init__(self, **kwargs):
|
| 16 |
-
super(
|
| 17 |
|
| 18 |
-
class
|
| 19 |
-
"
|
| 20 |
BUILDER_CONFIGS = [
|
| 21 |
-
|
| 22 |
-
DalaConfig(name="en-edo", version=datasets.Version("1.0.0"), description="dala english-edo dataset"),
|
| 23 |
-
DalaConfig(name="en-lng", version=datasets.Version("1.0.0"), description="dala english-lango dataset"),
|
| 24 |
-
DalaConfig(name="en-ijw", version=datasets.Version("1.0.0"), description="dala english-ijaw dataset"),
|
| 25 |
-
DalaConfig(name="en-its", version=datasets.Version("1.0.0"), description="dala english-itsekiri dataset"),
|
| 26 |
|
| 27 |
]
|
| 28 |
|
| 29 |
def _info(self):
|
| 30 |
-
source, target = self.config.name.split(
|
| 31 |
return datasets.DatasetInfo(
|
| 32 |
description=_DESCRIPTION,
|
| 33 |
-
features=datasets.Features({"translation": datasets.features.Translation(
|
| 34 |
-
supervised_keys=(source, target),
|
| 35 |
-
homepage="https://"
|
| 36 |
)
|
| 37 |
|
| 38 |
def _split_generators(self, dl_manager):
|
| 39 |
-
"
|
| 40 |
-
source, target = self.config.name.split(
|
| 41 |
-
if target in [
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
| 53 |
with open(filepath, encoding="utf-8") as f:
|
| 54 |
idx = 0
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
yield idx,
|
| 58 |
-
idx += 1
|
|
|
|
| 4 |
logger = datasets.logging.get_logger(__name__)
|
| 5 |
|
| 6 |
_DESCRIPTION = """
|
| 7 |
+
|
| 8 |
"""
|
| 9 |
|
| 10 |
+
_URL = "https://raw.githubusercontent.com/Dala-Group-A/etlPipeline/refs/heads/main/datasets/"
|
| 11 |
+
_TRAINING_FILE = "train.json"
|
| 12 |
|
| 13 |
+
class DafandConfig(datasets.BuilderConfig):
|
| 14 |
+
"""Builder config for dafand"""
|
| 15 |
def __init__(self, **kwargs):
|
| 16 |
+
super(DafandConfig, self).__init__(**kwargs)
|
| 17 |
|
| 18 |
+
class Dafand(datasets.GeneratorBasedBuilder):
|
| 19 |
+
"Dafand Datasets"
|
| 20 |
BUILDER_CONFIGS = [
|
| 21 |
+
DafandConfig(name="edo_english_bible", version=datasets.Version("1.0.0"), description="Dafand Edo English Bible"),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
]
|
| 24 |
|
| 25 |
def _info(self):
|
| 26 |
+
source, target, _= self.config.name.split('_')
|
| 27 |
return datasets.DatasetInfo(
|
| 28 |
description=_DESCRIPTION,
|
| 29 |
+
features=datasets.Features({"translation": datasets.features.Translation(languages=[source, target])}),
|
| 30 |
+
# supervised_keys=(source, target),
|
| 31 |
+
homepage="https://github.com/Dala-Group-A/etlPipeline/",
|
| 32 |
)
|
| 33 |
|
| 34 |
def _split_generators(self, dl_manager):
|
| 35 |
+
"Returns Split Generators"
|
| 36 |
+
source, target, _ = self.config.name.split("_")
|
| 37 |
+
# if target in ["edo", ]: # come here to update language names found in datasets
|
| 38 |
+
urls_to_download = {
|
| 39 |
+
"train": f"{_URL}{self.config.name}/{_TRAINING_FILE}",
|
| 40 |
+
}
|
| 41 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 42 |
+
return [
|
| 43 |
+
datasets.SplitGenerator(
|
| 44 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}, # ty:ignore[invalid-argument-type]
|
| 45 |
+
)
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
def _generate_examples(self, filepath): # ty:ignore[invalid-method-override]
|
| 49 |
+
logger.info("Generating examples from = %s", filepath)
|
| 50 |
with open(filepath, encoding="utf-8") as f:
|
| 51 |
idx = 0
|
| 52 |
+
src_tgt = json.load(f)
|
| 53 |
+
for line in src_tgt:
|
| 54 |
+
yield idx, line
|
| 55 |
+
idx += 1
|