tomrb commited on
Commit
f4de038
·
1 Parent(s): 2c18032
Files changed (1) hide show
  1. minipileoflaw.py +16 -9
minipileoflaw.py CHANGED
@@ -96,19 +96,26 @@ class MiniPileOfLaw(datasets.GeneratorBasedBuilder):
96
  ]
97
 
98
  def _generate_examples(self, filepaths):
99
- """This function returns the examples from JSON files, handling JSON Lines format."""
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)
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
 
 
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
+ # Skip empty lines
105
+ if not line.strip():
106
+ continue
107
+
108
+ try:
109
+ # Parse each line as a separate JSON object
110
+ item = json.loads(line.strip(), ensure_ascii=False)
111
+ yield {
112
+ "text": item.get("text", ""),
113
+ "created_timestamp": item.get("created_timestamp", ""),
114
+ "downloaded_timestamp": item.get("downloaded_timestamp", ""),
115
+ "url": item.get("url", "")
116
+ }
117
+ except json.JSONDecodeError as e:
118
+ print(f"Error parsing JSON on line in file {filepath}: {e}")
119
  except Exception as e:
120
  print(f"Error reading file {filepath}: {e}")
121