zaenal commited on
Commit
993c030
1 Parent(s): 4d30bab

add py files

Browse files
Files changed (1) hide show
  1. idnnews.py +55 -0
idnnews.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+ import datasets
4
+ import glob
5
+
6
+
7
+ _DESCRIPTION = """\
8
+ An open-source of Indonesian news from various portals from Dec 2022 to Sep 2021
9
+ """
10
+
11
+ _N_DATA_FILES = 4
12
+
13
+
14
+ _DATA_FILES = glob.glob('data/*00.txt.gz')
15
+
16
+
17
+ class IdnNewsScrap(datasets.GeneratorBasedBuilder):
18
+ """The Indonesian News Scrap dataset."""
19
+
20
+ BUILDER_CONFIGS = [
21
+ datasets.BuilderConfig(
22
+ name="plain_text",
23
+ description="Plain text",
24
+ version=datasets.Version("1.0.0"),
25
+ )
26
+ ]
27
+
28
+ def _info(self):
29
+ return datasets.DatasetInfo(
30
+ description=_DESCRIPTION,
31
+ features=datasets.Features({"text": datasets.Value("string")}),
32
+ )
33
+
34
+ def _split_generators(self, dl_manager):
35
+ archives = dl_manager.download(_DATA_FILES)
36
+ return [
37
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={
38
+ "archive_iterators": [
39
+ dl_manager.iter_archive(archive) for archive in archives
40
+ ],
41
+ "iter_archive": dl_manager.iter_archive
42
+ }),
43
+ ]
44
+
45
+ def _generate_examples(self, archive_iterators, iter_archive):
46
+ """Yields examples."""
47
+ for archive_iterator in archive_iterators:
48
+ for xz_filepath, xz_f in archive_iterator:
49
+ if not xz_filepath.endswith(".gz"):
50
+ continue
51
+ for txt_filepath, txt_f in iter_archive(xz_f):
52
+ if not txt_filepath.endswith(".txt"):
53
+ continue
54
+ idx = f"{xz_filepath}/{txt_filepath}"
55
+ yield idx, {"text": re.sub("\n\n\n+", "\n\n", txt_f.read().decode("utf-8")).strip()}