Skip to content

Fix bugs in main.py for English/German JSON conversion#405

Open
STACSEMTH wants to merge 1 commit intoagwaBom:mainfrom
STACSEMTH:main
Open

Fix bugs in main.py for English/German JSON conversion#405
STACSEMTH wants to merge 1 commit intoagwaBom:mainfrom
STACSEMTH:main

Conversation

@STACSEMTH
Copy link
Copy Markdown

@STACSEMTH STACSEMTH commented Nov 19, 2025

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.

  1. "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.

  2. "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".

  3. "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".

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