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

util: 파일로딩 인코딩 문제 수정 #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion chosung_translator/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from typing import List

from magic import Magic

CHOSUNG_LIST = ["ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"]


def load_data(file_path: str) -> List[str]:
texts = []
with open(file_path, "r") as f:
encoding_type = _get_file_encoding_type(file_path)
with open(file_path, "r", encoding=encoding_type) as f:
for line in f:
texts.append(line.strip())
return texts
Expand All @@ -19,3 +22,9 @@ def convert_text_to_chosung(text: str) -> str:
else:
chosung_text += c
return chosung_text


def _get_file_encoding_type(file_path: str) -> str:
blob = open(file_path, 'rb').read()
m = Magic(mime_encoding=True)
return m.from_buffer(blob)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
transformers
torch
tqdm
python-magic