juletxara commited on
Commit
0ab2363
1 Parent(s): 4f8b771

fix script to display dataset preview

Browse files
Files changed (1) hide show
  1. euscrawl.py +16 -16
euscrawl.py CHANGED
@@ -74,26 +74,26 @@ class EusCrawl(datasets.GeneratorBasedBuilder):
74
  )
75
 
76
  def _split_generators(self, dl_manager):
77
- path = dl_manager.download_and_extract(_URL)
78
- filepath = f"{path}/{_FILEPATH}"
79
  return [
80
  datasets.SplitGenerator(
81
  name=datasets.Split.TRAIN,
82
- gen_kwargs={"filepath": filepath},
83
  )
84
  ]
85
 
86
- def _generate_examples(self, filepath):
87
- with open(filepath, encoding="utf-8") as f:
88
- for id, line in enumerate(f):
89
- data = json.loads(line)
 
90
 
91
- # defaut to empty string if field is missing
92
- yield id, {
93
- "id": id,
94
- "title": data.get("title", ""),
95
- "text": data.get("text", ""),
96
- "source": data.get("source", ""),
97
- "license": data.get("license", ""),
98
- "url": data.get("url", ""),
99
- }
 
74
  )
75
 
76
  def _split_generators(self, dl_manager):
77
+ path = dl_manager.download(_URL)
 
78
  return [
79
  datasets.SplitGenerator(
80
  name=datasets.Split.TRAIN,
81
+ gen_kwargs={"filepaths": dl_manager.iter_archive(path)},
82
  )
83
  ]
84
 
85
+ def _generate_examples(self, filepaths):
86
+ for filepath, file in filepaths:
87
+ if filepath == _FILEPATH:
88
+ for id, line in enumerate(file):
89
+ data = json.loads(line)
90
 
91
+ # defaut to empty string if field is missing
92
+ yield id, {
93
+ "id": id,
94
+ "title": data.get("title", ""),
95
+ "text": data.get("text", ""),
96
+ "source": data.get("source", ""),
97
+ "license": data.get("license", ""),
98
+ "url": data.get("url", ""),
99
+ }