-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjective2.txt
52 lines (37 loc) · 4.01 KB
/
objective2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
referencing this repository by search: https://github.com/acmeism/RosettaCodeData
**Objective:**
Create a Python script that navigates the Rosetta Code Data repository, cloned from https://github.com/acmeism/RosettaCodeData then reads the text files in each task directory, and generates a JSON file containing the task description and 5 pairs of randomly selected solutions for each task. The script should handle the following:
* Navigate the directory structure of the Rosetta Code Data repository, which includes a top-level directory containing task directories, each of which contains language directories with text files.
* Read the text files in each task directory, which may have different formatting but are all text files.
* Handle any encoding issues that may arise when reading the text files.
* Generate a JSON file containing pairs of randomly selected solutions for each task, with each pair consisting of two text files from the same task directory.
* Start a new, numbered json file whenever the current file reaches 48 megabytes
**Additional Considerations:**
* The script should be able to handle the specific directory structure of the Rosetta Code Data repository.
* The script should be able to read and process text files with different formatting.
* The script should handle any encoding issues that may arise when reading the text files.
* The script should generate a JSON file that is properly formatted and can be easily read and processed.
Improved Object Prompt: Processing Rosetta Code Data
Objective:
Develop a Python script to process text files from the Rosetta Code data repository and generate JSON files containing pairs of solutions for each task.
Important Features:
Directory Traversal: Efficiently iterate through the directory structure containing task subdirectories and language-specific text files.
File Handling: Open, read, and decode text files using appropriate encoding techniques (consider using chardet for auto-detection). Handle potential errors like missing files or decoding issues.
Data Processing: Extract solution content from text files and create a list of solutions for each task.
Random Pairing: Generate a user-defined number (e.g., 5) of random solution pairs for each task.
JSON Generation: Create a JSON object for each task with properties like "task_name" and "solution_pairs" containing the randomly selected pairs.
Large File Handling: Split the generated JSON data into multiple files if the total size exceeds a defined limit (e.g., 48 MB).
Error Handling: Implement robust error handling to catch potential exceptions (e.g., file not found, decode errors, JSON writing errors) and log informative messages for debugging.
Optional Features:
Limit the number of tasks processed for testing purposes using a TASK_LIMIT constant.
Consider using a cache or dictionary to store processed file content for efficiency within a task directory.
Implement logging using a library like logging to record processing information and errors.
Fixes for Identified Problems:
Missing Encoding Detection: Implement chardet to detect the encoding of text files before reading to avoid decoding errors.
Limited Error Handling: Improve error handling to catch and log specific errors with file paths for easier debugging.
Redundant File Reading: Introduce a cache (processed_files) to store processed file content within a task directory, avoiding unnecessary re-reading.
Inefficient JSON Size Estimation: Simplify the JSON size calculation using json.dumps with minimal separators to improve accuracy of the size estimation.
Additional Notes:
The script should be modular with well-defined functions for specific tasks (e.g., process_task_directory, random_pairs, save_json).
Consider using clear variable names and comments to enhance code readability and maintainability.
By incorporating these features and addressing the identified issues, the script will be more robust, efficient, and easier to debug.