| import csv, datasets, os |
|
|
| class Voaburmese(datasets.GeneratorBasedBuilder): |
| VERSION = datasets.Version("1.0.0") |
|
|
| _SLOT2IDX = {"morning": 0, "evening": 1} |
|
|
| def _info(self): |
| return datasets.DatasetInfo( |
| description="VOA Burmese Morning & Evening audio index (2012-09-16 → today)", |
| license="odc-pddl-1.0", |
| features=datasets.Features( |
| { |
| "id": datasets.Value("string"), |
| "date": datasets.Value("string"), |
| "slot": datasets.ClassLabel(names=["morning", "evening"]), |
| "title": datasets.Value("string"), |
| "article_url": datasets.Value("string"), |
| "audio": datasets.Audio(), |
| } |
| ), |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| |
| csv_path = os.path.join(self._get_manual_data_dir(), "index.csv") |
| return [datasets.SplitGenerator(name="train", gen_kwargs={"csv_path": csv_path})] |
|
|
| def _generate_examples(self, csv_path): |
| with open(csv_path, newline="", encoding="utf-8") as f: |
| for i, row in enumerate(csv.DictReader(f)): |
| yield i, { |
| "id": f"{row['date']}_{row['slot']}", |
| "date": row["date"], |
| "slot": self._SLOT2IDX[row["slot"]], |
| "title": row["title"], |
| "article_url": row["article_url"], |
| "audio": row["mp3_url"], |
| } |