sadrasabouri commited on
Commit
2dd6344
1 Parent(s): 1511ed6

Update naab-raw.py

Browse files
Files changed (1) hide show
  1. naab-raw.py +47 -24
naab-raw.py CHANGED
@@ -47,9 +47,6 @@ _BASE_URL = "https://huggingface.co/datasets/SLPL/naab/resolve/main/data/"
47
  _CORPUS_URLS = {
48
  "CC-fa": "https://storage.googleapis.com/danielk-files/farsi-text/merged_files/commoncrawl_fa_merged.txt",
49
  }
50
- _URLS = {
51
- "train": list(_CORPUS_URLS.values()),
52
- }
53
  VERSION = datasets.Version("1.0.0")
54
 
55
 
@@ -73,6 +70,10 @@ class NaabRawConfig(datasets.GeneratorBasedBuilder):
73
  version=VERSION,
74
  description=_DESCRIPTION)
75
  ]
 
 
 
 
76
  BUILDER_CONFIG_CLASS = NaabRawConfig
77
 
78
  DEFAULT_CONFIG_NAME = "all"
@@ -91,27 +92,49 @@ class NaabRawConfig(datasets.GeneratorBasedBuilder):
91
  )
92
 
93
  def _split_generators(self, dl_manager):
94
- data_urls = {
95
- "train": _URLS["train"]
96
- }
97
-
98
- downloaded_files = dl_manager.download(data_urls["train"])
99
- return [
100
- datasets.SplitGenerator(
101
- name=datasets.Split.TRAIN,
102
- gen_kwargs={
103
- "filepaths": downloaded_files,
104
- "split": "train"
105
- }
106
- )
107
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
 
110
  def _generate_examples(self, filepaths, split):
111
- for filepath in filepaths:
112
- with open(filepath, encoding="utf-8") as f:
113
- for key, row in enumerate(f):
114
- if row.strip():
115
- yield key, {"text": row}
116
- else:
117
- yield key, {"text": ""}
 
 
 
 
 
 
 
 
 
47
  _CORPUS_URLS = {
48
  "CC-fa": "https://storage.googleapis.com/danielk-files/farsi-text/merged_files/commoncrawl_fa_merged.txt",
49
  }
 
 
 
50
  VERSION = datasets.Version("1.0.0")
51
 
52
 
 
70
  version=VERSION,
71
  description=_DESCRIPTION)
72
  ]
73
+ BUILDER_CONFIGS.extend([NaabRawConfig(
74
+ name=key,
75
+ version=VERSION,
76
+ description=_DESCRIPTION) for key in _CORPUS_URLS.keys()])
77
  BUILDER_CONFIG_CLASS = NaabRawConfig
78
 
79
  DEFAULT_CONFIG_NAME = "all"
 
92
  )
93
 
94
  def _split_generators(self, dl_manager):
95
+ if self.config.name == "all":
96
+ data_urls = {
97
+ "train": list(_CORPUS_URLS.values())
98
+ }
99
+ downloaded_files = dl_manager.download(data_urls["train"])
100
+ return [
101
+ datasets.SplitGenerator(
102
+ name=datasets.Split.TRAIN,
103
+ gen_kwargs={
104
+ "filepaths": downloaded_files,
105
+ "split": "train"
106
+ }
107
+ )
108
+ ]
109
+ else:
110
+ data_urls = {
111
+ "train": _CORPUS_URLS[self.config.name]
112
+ }
113
+ downloaded_files = dl_manager.download(data_urls["train"])
114
+ return [
115
+ datasets.SplitGenerator(
116
+ name=datasets.Split.TRAIN,
117
+ gen_kwargs={
118
+ "filepath": downloaded_files,
119
+ "split": "train"
120
+ }
121
+ )
122
+ ]
123
 
124
 
125
  def _generate_examples(self, filepaths, split):
126
+ if self.config.name == "all":
127
+ for filepath in filepaths:
128
+ with open(filepath, encoding="utf-8") as f:
129
+ for key, row in enumerate(f):
130
+ if row.strip():
131
+ yield key, {"text": row}
132
+ else:
133
+ yield key, {"text": ""}
134
+ else:
135
+ with open(filepaths, encoding="utf-8") as f:
136
+ for key, row in enumerate(f):
137
+ if row.strip():
138
+ yield key, {"text": row}
139
+ else:
140
+ yield key, {"text": ""}