idn-news-az / idnnews.py
zaenal
add py files
993c030
raw
history blame
No virus
1.69 kB
import re
import datasets
import glob
_DESCRIPTION = """\
An open-source of Indonesian news from various portals from Dec 2022 to Sep 2021
"""
_N_DATA_FILES = 4
_DATA_FILES = glob.glob('data/*00.txt.gz')
class IdnNewsScrap(datasets.GeneratorBasedBuilder):
"""The Indonesian News Scrap dataset."""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="plain_text",
description="Plain text",
version=datasets.Version("1.0.0"),
)
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({"text": datasets.Value("string")}),
)
def _split_generators(self, dl_manager):
archives = dl_manager.download(_DATA_FILES)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={
"archive_iterators": [
dl_manager.iter_archive(archive) for archive in archives
],
"iter_archive": dl_manager.iter_archive
}),
]
def _generate_examples(self, archive_iterators, iter_archive):
"""Yields examples."""
for archive_iterator in archive_iterators:
for xz_filepath, xz_f in archive_iterator:
if not xz_filepath.endswith(".gz"):
continue
for txt_filepath, txt_f in iter_archive(xz_f):
if not txt_filepath.endswith(".txt"):
continue
idx = f"{xz_filepath}/{txt_filepath}"
yield idx, {"text": re.sub("\n\n\n+", "\n\n", txt_f.read().decode("utf-8")).strip()}