tomrb commited on
Commit
d711d0d
·
1 Parent(s): ecd0e91
Files changed (1) hide show
  1. minipileoflaw.py +13 -13
minipileoflaw.py CHANGED
@@ -94,21 +94,21 @@ class MiniPileOfLaw(datasets.GeneratorBasedBuilder):
94
  name=datasets.Split.VALIDATION, gen_kwargs={"filepaths": validation_downloaded_files}
95
  ),
96
  ]
97
-
98
-
99
-
100
  def _generate_examples(self, filepaths):
101
- """This function returns the examples from CSV files, handling escape characters."""
102
  for filepath in filepaths:
103
  try:
104
- # Reading the CSV file with the appropriate escape character
105
- df = pd.read_csv(filepath, escapechar='\\')
106
- for _, row in df.iterrows():
107
- yield {
108
- "text": row.get("text", ""),
109
- "created_timestamp": row.get("created_timestamp", ""),
110
- "downloaded_timestamp": row.get("downloaded_timestamp", ""),
111
- "url": row.get("url", "")
112
- }
 
113
  except Exception as e:
114
  print(f"Error reading file {filepath}: {e}")
 
 
94
  name=datasets.Split.VALIDATION, gen_kwargs={"filepaths": validation_downloaded_files}
95
  ),
96
  ]
97
+
 
 
98
  def _generate_examples(self, filepaths):
99
+ """This function returns the examples from JSONL files, with each line being a separate JSON object."""
100
  for filepath in filepaths:
101
  try:
102
+ with open(filepath, 'r', encoding='utf-8') as file:
103
+ for line in file:
104
+ # Parse each line as a separate JSON object
105
+ item = json.loads(line.strip())
106
+ yield {
107
+ "text": item.get("text", ""),
108
+ "created_timestamp": item.get("created_timestamp", ""),
109
+ "downloaded_timestamp": item.get("downloaded_timestamp", ""),
110
+ "url": item.get("url", "")
111
+ }
112
  except Exception as e:
113
  print(f"Error reading file {filepath}: {e}")
114
+