Fix bugs in main.py for English/German JSON conversion#405
Open
STACSEMTH wants to merge 1 commit intoagwaBom:mainfrom
Open
Fix bugs in main.py for English/German JSON conversion#405STACSEMTH wants to merge 1 commit intoagwaBom:mainfrom
STACSEMTH wants to merge 1 commit intoagwaBom:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix multiple bugs in "main.py" so that it correctly reads the input files, converts English/German sentence pairs into valid JSON lines, and writes the expected "concated.json" output.
"Fixed 'path_to_file_list' to actually read the file contents"
In the original implementation, "path_to_file_list" opened the file in write mode ('w') and returned an undefined variable (lines), which erased the input file and raised a "NameError".
Therefore, I changed it to open the file in read mode ('r') and return a list of lines (with trailing newlines stripped), so the function now correctly loads the input data.
"Corrected JSON escaping and template construction in 'train_file_list_to_json'"
The original "process_file" function did not properly escape backslashes and used a condition (if '/' or ' " ' in file) that is always true.
So, I replaced this logic with explicit replacements so that "\", "/", and """ are converted to "\\", "\/", and \" respectively.
In addition, the JSON template previously used the
"German"key twice and did not assemble a valid JSON string.I updated the template to produce {"English":"...","German":"..."} and now build each JSON line as
"template_start + English + template_mid + German + template_end".
"Fixed file writing and main function flow"
The original "write_file_list" opened the output file in read mode ('r') and only wrote newline characters, so no actual content was saved.
So, I changed it to open the file in write mode ('w') and write each string from the list as a separate line.
Finally, in "main", the functions were called with incorrect arguments: "train_file_list_to_json" was given a file path instead of two lists, and "path_to_file_list" was called with lists instead of a path.
I updated "main" so that it (1) reads "english.txt" and "german.txt" using "path_to_file_list", (2) passes the two lists to "train_file_list_to_json", and (3) writes the resulting JSON lines to "concated.json" using "write_file_list".