Skip to content

Fix main.py to correctly generate concated.json#402

Open
hs-chang wants to merge 1 commit intoagwaBom:mainfrom
hs-chang:main
Open

Fix main.py to correctly generate concated.json#402
hs-chang wants to merge 1 commit intoagwaBom:mainfrom
hs-chang:main

Conversation

@hs-chang
Copy link
Copy Markdown

(1) What line of code I changed

  • path_to_file_list:

    • I changed the function so that it opens the file in read mode and returns all lines from the file as a list instead of opening in write mode and returning an undefined variable.
  • train_file_list_to_json:

    • I rewrote the logic so that each English line and German line are properly escaped for JSON (backslash, slash, and double quotes) and formatted as {"English":"...","German":"..."}.
    • I also removed the bug where the English line was overwritten by the German line and fixed the incorrect JSON template that used "German" twice.
  • write_file_list:

    • I changed the function to open the output file in write mode and actually write each JSON string from the list to the output file, one per line.

(2) Why it is wrong code

  • path_to_file_list originally opened the file with mode 'w' and returned an undefined variable 'lines', which means the file content was never read and the file could even be truncated.
  • train_file_list_to_json overwrote the English text with the German text and used an incorrect JSON template (it used "German" twice and did not escape special characters properly), so the output did not match the required concated.json format.
  • write_file_list opened the file in read mode and then used f.write(), which would cause an error and also did not write the processed list of JSON strings to the output file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant