tomrb commited on
Commit
e0b55da
·
1 Parent(s): 56feadb

mod loading script

Browse files
Files changed (1) hide show
  1. minipileoflaw.py +15 -15
minipileoflaw.py CHANGED
@@ -3,6 +3,7 @@
3
 
4
  import gzip
5
  import json
 
6
 
7
  import datasets
8
  try:
@@ -90,23 +91,22 @@ class MiniPileOfLaw(datasets.GeneratorBasedBuilder):
90
  ),
91
  ]
92
 
 
93
  def _generate_examples(self, filepaths):
94
- """This function returns the examples in the raw (text) form by iterating on all the files."""
95
  id_ = 0
96
  for filepath in filepaths:
97
  logger.info("Generating examples from = %s", filepath)
98
  try:
99
- with xz.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
100
- for line in f:
101
- if line:
102
- example = json.loads(line)
103
- if example is not None and isinstance(example, dict):
104
- yield id_, {
105
- "text": example.get("text", ""),
106
- "created_timestamp": example.get("created_timestamp", ""),
107
- "downloaded_timestamp": example.get("downloaded_timestamp", ""),
108
- "url": example.get("url", "")
109
- }
110
- id_ += 1
111
- except:
112
- print("Error reading file:", filepath)
 
3
 
4
  import gzip
5
  import json
6
+ import csv
7
 
8
  import datasets
9
  try:
 
91
  ),
92
  ]
93
 
94
+
95
  def _generate_examples(self, filepaths):
96
+ """This function returns the examples in the raw (text) form by iterating on all the CSV files."""
97
  id_ = 0
98
  for filepath in filepaths:
99
  logger.info("Generating examples from = %s", filepath)
100
  try:
101
+ with open(filepath, "r", encoding="utf-8") as file:
102
+ reader = csv.DictReader(file)
103
+ for row in reader:
104
+ yield id_, {
105
+ "text": row.get("text", ""),
106
+ "created_timestamp": row.get("created_timestamp", ""),
107
+ "downloaded_timestamp": row.get("downloaded_timestamp", ""),
108
+ "url": row.get("url", "")
109
+ }
110
+ id_ += 1
111
+ except Exception as e:
112
+ print(f"Error reading file: {filepath}, Error: {e}")