- minipileoflaw.py +12 -13
minipileoflaw.py
CHANGED
@@ -99,17 +99,16 @@ class MiniPileOfLaw(datasets.GeneratorBasedBuilder):
|
|
99 |
for filepath in filepaths:
|
100 |
logger.info("Generating examples from = %s", filepath)
|
101 |
try:
|
102 |
-
with
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
id_ += 1
|
114 |
except:
|
115 |
-
print("Error reading file:", filepath)
|
|
|
99 |
for filepath in filepaths:
|
100 |
logger.info("Generating examples from = %s", filepath)
|
101 |
try:
|
102 |
+
with open(filepath, "r", encoding="utf-8") as f:
|
103 |
+
data = json.load(f) # Load the entire JSON file
|
104 |
+
for example in data: # Iterate over items if the file contains a list of dictionaries
|
105 |
+
if example is not None and isinstance(example, dict):
|
106 |
+
yield id_, {
|
107 |
+
"text": example.get("text", ""),
|
108 |
+
"created_timestamp": example.get("created_timestamp", ""),
|
109 |
+
"downloaded_timestamp": example.get("downloaded_timestamp", ""),
|
110 |
+
"url": example.get("url", "")
|
111 |
+
}
|
112 |
+
id_ += 1
|
|
|
113 |
except:
|
114 |
+
print("Error reading file:", filepath)
|