albertvillanova HF staff commited on
Commit
37e51f3
1 Parent(s): e464ca5

Update loading script

Browse files
Files changed (1) hide show
  1. bionlp_st_2011_epi.py +21 -22
bionlp_st_2011_epi.py CHANGED
@@ -15,7 +15,7 @@
15
 
16
 
17
  from pathlib import Path
18
- from typing import List
19
 
20
  import datasets
21
 
@@ -62,8 +62,9 @@ _HOMEPAGE = "https://github.com/openbiocorpora/bionlp-st-2011-epi"
62
  _LICENSE = 'GENIA Project License for Annotated Corpora'
63
 
64
  _URLs = {
65
- "source": "https://github.com/openbiocorpora/bionlp-st-2011-epi/archive/refs/heads/master.zip",
66
- "bigbio_kb": "https://github.com/openbiocorpora/bionlp-st-2011-epi/archive/refs/heads/master.zip",
 
67
  }
68
 
69
  _SUPPORTED_TASKS = [
@@ -198,46 +199,44 @@ class bionlp_st_2011_epi(datasets.GeneratorBasedBuilder):
198
  self, dl_manager: datasets.DownloadManager
199
  ) -> List[datasets.SplitGenerator]:
200
 
201
- my_urls = _URLs[self.config.schema]
202
- data_dir = Path(dl_manager.download_and_extract(my_urls))
203
- data_files = {
204
- "train": data_dir
205
- / f"bionlp-st-2011-epi-master"
206
- / "original-data"
207
- / "train",
208
- "dev": data_dir / f"bionlp-st-2011-epi-master" / "original-data" / "devel",
209
- "test": data_dir / f"bionlp-st-2011-epi-master" / "original-data" / "test",
210
- }
211
-
212
  return [
213
  datasets.SplitGenerator(
214
  name=datasets.Split.TRAIN,
215
- gen_kwargs={"data_files": data_files["train"]},
216
  ),
217
  datasets.SplitGenerator(
218
  name=datasets.Split.VALIDATION,
219
- gen_kwargs={"data_files": data_files["dev"]},
220
  ),
221
  datasets.SplitGenerator(
222
  name=datasets.Split.TEST,
223
- gen_kwargs={"data_files": data_files["test"]},
224
  ),
225
  ]
226
 
227
- def _generate_examples(self, data_files: Path):
228
  if self.config.schema == "source":
229
- txt_files = list(data_files.glob("*txt"))
230
- for guid, txt_file in enumerate(txt_files):
 
 
 
231
  example = parse_brat_file(txt_file)
232
  example["id"] = str(guid)
233
  yield guid, example
 
234
  elif self.config.schema == "bigbio_kb":
235
- txt_files = list(data_files.glob("*txt"))
236
- for guid, txt_file in enumerate(txt_files):
 
 
 
237
  example = brat_parse_to_bigbio_kb(
238
  parse_brat_file(txt_file)
239
  )
240
  example["id"] = str(guid)
241
  yield guid, example
 
242
  else:
243
  raise ValueError(f"Invalid config: {self.config.name}")
 
15
 
16
 
17
  from pathlib import Path
18
+ from typing import Iterable, List
19
 
20
  import datasets
21
 
 
62
  _LICENSE = 'GENIA Project License for Annotated Corpora'
63
 
64
  _URLs = {
65
+ "train": "data/train.zip",
66
+ "validation": "data/devel.zip",
67
+ "test": "data/test.zip",
68
  }
69
 
70
  _SUPPORTED_TASKS = [
 
199
  self, dl_manager: datasets.DownloadManager
200
  ) -> List[datasets.SplitGenerator]:
201
 
202
+ data_files = dl_manager.download_and_extract(_URLs)
 
 
 
 
 
 
 
 
 
 
203
  return [
204
  datasets.SplitGenerator(
205
  name=datasets.Split.TRAIN,
206
+ gen_kwargs={"data_files": dl_manager.iter_files(data_files["train"])},
207
  ),
208
  datasets.SplitGenerator(
209
  name=datasets.Split.VALIDATION,
210
+ gen_kwargs={"data_files": dl_manager.iter_files(data_files["validation"])},
211
  ),
212
  datasets.SplitGenerator(
213
  name=datasets.Split.TEST,
214
+ gen_kwargs={"data_files": dl_manager.iter_files(data_files["test"])},
215
  ),
216
  ]
217
 
218
+ def _generate_examples(self, data_files: Iterable[str]):
219
  if self.config.schema == "source":
220
+ guid = 0
221
+ for data_file in data_files:
222
+ txt_file = Path(data_file)
223
+ if txt_file.suffix != ".txt":
224
+ continue
225
  example = parse_brat_file(txt_file)
226
  example["id"] = str(guid)
227
  yield guid, example
228
+ guid += 1
229
  elif self.config.schema == "bigbio_kb":
230
+ guid = 0
231
+ for data_file in data_files:
232
+ txt_file = Path(data_file)
233
+ if txt_file.suffix != ".txt":
234
+ continue
235
  example = brat_parse_to_bigbio_kb(
236
  parse_brat_file(txt_file)
237
  )
238
  example["id"] = str(guid)
239
  yield guid, example
240
+ guid += 1
241
  else:
242
  raise ValueError(f"Invalid config: {self.config.name}")