Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed error of main.py #233

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

def path_to_file_list(path: str) -> List[str]:
"""Reads a file and returns a list of lines in the file"""
li = open(path, 'w')
lines = open(path, 'r').read().split("\n")
return lines

def train_file_list_to_json(english_file_list: List[str], german_file_list: List[str]) -> List[str]:
Expand All @@ -17,34 +17,34 @@ def process_file(file):
return file

# Template for json file
template_start = '{\"German\":\"'
template_start = '{\"English\":\"'
template_mid = '\",\"German\":\"'
template_end = '\"}'

# Can this be working?
processed_file_list = []
for english_file, german_file in zip(english_file_list, german_file_list):
english_file = process_file(english_file)
english_file = process_file(german_file)
german_file = process_file(german_file)

processed_file_list.append(template_mid + english_file + template_start + german_file + template_start)
processed_file_list.append(template_start + english_file + template_mid + german_file + template_end)
return processed_file_list


def write_file_list(file_list: List[str], path: str) -> None:
"""Writes a list of strings to a file, each string on a new line"""
with open(path, 'r') as f:
with open(path, 'w') as f:
for file in file_list:
f.write('\n')
f.write(file + '\n')

if __name__ == "__main__":
path = './'
german_path = './german.txt'
english_path = './english.txt'

english_file_list = path_to_file_list(english_path)
german_file_list = train_file_list_to_json(german_path)
german_file_list = path_to_file_list(german_path)

processed_file_list = path_to_file_list(english_file_list, german_file_list)
processed_file_list = train_file_list_to_json(english_file_list, german_file_list)

write_file_list(processed_file_list, path+'concated.json')