Datasets:
Upload knessetCorpus.py
Browse files- knessetCorpus.py +37 -12
knessetCorpus.py
CHANGED
@@ -336,11 +336,36 @@ class KnessetCorpus(datasets.GeneratorBasedBuilder):
|
|
336 |
urls = self.config.data_urls
|
337 |
downloaded_files = dl_manager.download_and_extract(urls)
|
338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
return [
|
340 |
datasets.SplitGenerator(
|
341 |
name=datasets.Split.TRAIN,
|
342 |
gen_kwargs={
|
343 |
-
"data_files":
|
344 |
},
|
345 |
),
|
346 |
]
|
@@ -373,17 +398,17 @@ class KnessetCorpus(datasets.GeneratorBasedBuilder):
|
|
373 |
sample[feature] = row[feature]
|
374 |
|
375 |
# Handle nested structures (e.g., `protocol_sentences`)
|
376 |
-
if "protocol_sentences" in row:
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
else:
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
except Exception as e:
|
388 |
print(f"Error opening file '{filepath}': {e}. Skipping.")
|
389 |
|
|
|
336 |
urls = self.config.data_urls
|
337 |
downloaded_files = dl_manager.download_and_extract(urls)
|
338 |
|
339 |
+
# Handle single file case
|
340 |
+
if not isinstance(downloaded_files, list):
|
341 |
+
downloaded_files = [downloaded_files]
|
342 |
+
|
343 |
+
# Only process if we detect zip files
|
344 |
+
if any('zip://' in str(file) for file in downloaded_files):
|
345 |
+
extracted_files = []
|
346 |
+
for file_path in downloaded_files:
|
347 |
+
# Remove the zip:// prefix and download the actual zip content
|
348 |
+
actual_url = str(file_path).replace('zip://::', '')
|
349 |
+
extracted = dl_manager.download_and_extract(actual_url)
|
350 |
+
|
351 |
+
# If it's a directory, get all files inside
|
352 |
+
if os.path.isdir(extracted):
|
353 |
+
for root, _, files in os.walk(extracted):
|
354 |
+
for filename in files:
|
355 |
+
full_path = os.path.join(root, filename)
|
356 |
+
extracted_files.append(full_path)
|
357 |
+
else:
|
358 |
+
extracted_files.append(extracted)
|
359 |
+
|
360 |
+
data_files = extracted_files
|
361 |
+
else:
|
362 |
+
data_files = downloaded_files
|
363 |
+
|
364 |
return [
|
365 |
datasets.SplitGenerator(
|
366 |
name=datasets.Split.TRAIN,
|
367 |
gen_kwargs={
|
368 |
+
"data_files": data_files,
|
369 |
},
|
370 |
),
|
371 |
]
|
|
|
398 |
sample[feature] = row[feature]
|
399 |
|
400 |
# Handle nested structures (e.g., `protocol_sentences`)
|
401 |
+
# if "protocol_sentences" in row:
|
402 |
+
# protocol_sentences = row.get("protocol_sentences", [])
|
403 |
+
# for sentence in protocol_sentences:
|
404 |
+
# sentence_id = sentence.get("sentence_id", None)
|
405 |
+
# if sentence_id:
|
406 |
+
# yield sentence_id, sentence
|
407 |
+
# else:
|
408 |
+
try:
|
409 |
+
yield id_, sample
|
410 |
+
except Exception as e:
|
411 |
+
print(f'couldnt yield sample. error: {e}. sample is: {sample}.', flush=True)
|
412 |
except Exception as e:
|
413 |
print(f"Error opening file '{filepath}': {e}. Skipping.")
|
414 |
|