Datasets:

toniwuest commited on
Commit
15a6813
·
verified ·
1 Parent(s): 674794b

Update CLEVR-Sudoku.py

Browse files
Files changed (1) hide show
  1. CLEVR-Sudoku.py +38 -18
CLEVR-Sudoku.py CHANGED
@@ -105,7 +105,7 @@ class CLEVRSudoku(datasets.GeneratorBasedBuilder):
105
  return [
106
  datasets.SplitGenerator(
107
  name=datasets.Split.TRAIN,
108
- gen_kwargs={"archive_path": archive_path, "dl_manager": dl_manager}
109
  )
110
  ]
111
 
@@ -136,27 +136,47 @@ class CLEVRSudoku(datasets.GeneratorBasedBuilder):
136
  """Yields examples from the archive, assuming JSON files inside a 'json' folder."""
137
  print("archive path in generate examples")
138
  print(type(archive_path))
139
- # This uses `dl_manager.iter_archive` to iterate over files in the archive
140
- with open(archive_path, "rb") as f:
141
- for i, (file_name, file_handle) in enumerate(dl_manager.iter_archive(f)):
142
- # Only process files that are in the 'json/' folder and end with '.json'
143
- if file_name.startswith("json/") and file_name.endswith(".json"):
144
 
145
- print(i, file_handle)
 
 
 
146
 
147
- # Read and parse the JSON content
148
- json_content = json.load(file_handle)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
- # Extract the specific fields from the JSON
151
- extracted_data = {
152
- # "file_name": file_name, # The name of the file inside the archive
153
- "id": i, # Extract the 'id' field
154
- # "name": json_content.get("name"), # Extract the 'name' field
155
- # "solution": json_content.get("solution") # Extract the 'puzzle' field
156
- }
157
 
158
- # Yield the extracted data
159
- yield i, extracted_data
160
 
161
  # for i, (sudoku, opt, label, attr) in enumerate(
162
  # zip(sudokus, options, labels, attributes)
 
105
  return [
106
  datasets.SplitGenerator(
107
  name=datasets.Split.TRAIN,
108
+ gen_kwargs={"archive_path": archive_path_iter_archive, "dl_manager": dl_manager}
109
  )
110
  ]
111
 
 
136
  """Yields examples from the archive, assuming JSON files inside a 'json' folder."""
137
  print("archive path in generate examples")
138
  print(type(archive_path))
 
 
 
 
 
139
 
140
+ for i, (file_path, file_obj) in enumerate(archive_path):
141
+ print(file_path)
142
+ if file_path.startswith("json/") and file_path.endswith(".json"):
143
+ print(i, file_path)
144
 
145
+ # Read and parse the JSON content
146
+ json_content = json.load(file_obj)
147
+
148
+ # Extract the specific fields from the JSON
149
+ extracted_data = {
150
+ # "file_name": file_name, # The name of the file inside the archive
151
+ "id": i, # Extract the 'id' field
152
+ # "name": json_content.get("name"), # Extract the 'name' field
153
+ #"solution": json_content.get("solution") # Extract the 'puzzle' field
154
+ }
155
+
156
+ # Yield the extracted data
157
+ yield i, extracted_data
158
+
159
+ # # This uses `dl_manager.iter_archive` to iterate over files in the archive
160
+ # with open(archive_path, "rb") as f:
161
+ # for i, (file_name, file_handle) in enumerate(dl_manager.iter_archive(f)):
162
+ # # Only process files that are in the 'json/' folder and end with '.json'
163
+ # if file_name.startswith("json/") and file_name.endswith(".json"):
164
+
165
+ # print(i, file_handle)
166
+
167
+ # # Read and parse the JSON content
168
+ # json_content = json.load(file_handle)
169
 
170
+ # # Extract the specific fields from the JSON
171
+ # extracted_data = {
172
+ # # "file_name": file_name, # The name of the file inside the archive
173
+ # "id": i, # Extract the 'id' field
174
+ # # "name": json_content.get("name"), # Extract the 'name' field
175
+ # # "solution": json_content.get("solution") # Extract the 'puzzle' field
176
+ # }
177
 
178
+ # # Yield the extracted data
179
+ # yield i, extracted_data
180
 
181
  # for i, (sudoku, opt, label, attr) in enumerate(
182
  # zip(sudokus, options, labels, attributes)