MCPcopy Create free account
hub / github.com/ZinYY/TreeLoRA / process_directory

Function process_directory

assist_scripts/format_json.py:53–89  ·  view source on GitHub ↗
(directory_path)

Source from the content-addressed store, hash-verified

51
52
53def process_directory(directory_path):
54 # Convert to Path object for easier path handling
55 dir_path = Path(directory_path)
56
57 # Expected files
58 expected_files = {'dev.json', 'train.json', 'test.json', 'labels.json'}
59
60 # Get all JSON files in directory
61 json_files = {f.name for f in dir_path.glob('*.json')}
62
63 # Check if directory contains exactly the expected files
64 if json_files != expected_files:
65 missing_files = expected_files - json_files
66 extra_files = json_files - expected_files
67 error_msg = []
68 if missing_files:
69 error_msg.append(f"Missing files: {', '.join(missing_files)}")
70 if extra_files:
71 error_msg.append(f"Unexpected files: {', '.join(extra_files)}")
72 raise ValueError(f"Directory does not contain exactly the expected files.\n" + "\n".join(error_msg))
73
74 # Process files except label.json
75 for json_file in dir_path.glob('*.json'):
76 if json_file.name == 'labels.json':
77 continue
78
79 # Create backup of original file
80 backup_path = json_file.parent / f'raw_{json_file.name}'
81 shutil.copy2(json_file, backup_path)
82
83 # Determine output filename
84 output_name = 'eval.json' if json_file.name == 'dev.json' else json_file.name
85 output_path = json_file.parent / output_name
86
87 # Process the file
88 transform_json(str(json_file), str(output_path))
89 print(f'Processed: {json_file.name} -> {output_name}')
90
91
92if __name__ == '__main__':

Callers 1

format_json.pyFile · 0.85

Calls 1

transform_jsonFunction · 0.85

Tested by

no test coverage detected