ginipick commited on
Commit
c70cf42
·
verified ·
1 Parent(s): 0082fef

Update src/main.py

Browse files
Files changed (1) hide show
  1. src/main.py +11 -5
src/main.py CHANGED
@@ -91,7 +91,7 @@ def translate_korean_text(text):
91
  "sl": "ko",
92
  "tl": "en",
93
  "dt": "t",
94
- "q": text.replace(f"'{quoted_word}'", "NAME") # 임시로 'NAME'으로 대체
95
  }
96
  response = requests.get(url, params=params)
97
  if response.status_code != 200:
@@ -100,7 +100,8 @@ def translate_korean_text(text):
100
  translated_text = ' '.join(item[0] for item in response.json()[0] if item[0])
101
 
102
  # 3. 따옴표 안의 단어 처리
103
- if re.match(r'^[A-Za-z]+$', quoted_word): # 영어 단어인 경우
 
104
  proper_noun = quoted_word.upper()
105
  else: # 한글 단어인 경우
106
  params["q"] = quoted_word
@@ -111,9 +112,14 @@ def translate_korean_text(text):
111
  proper_noun = quoted_word.upper()
112
 
113
  # 4. 최종 문장 조합
114
- final_text = translated_text.replace("NAME", f"'{proper_noun}'")
115
- if "name is" in final_text.lower(): # 이름 관련 문장인 경우
116
- final_text = re.sub(r"name is\s+'", "name is '", final_text, flags=re.IGNORECASE)
 
 
 
 
 
117
 
118
  return final_text
119
 
 
91
  "sl": "ko",
92
  "tl": "en",
93
  "dt": "t",
94
+ "q": text.replace(f"'{quoted_word}'", "XXXXX") # 특수한 마커로 대체
95
  }
96
  response = requests.get(url, params=params)
97
  if response.status_code != 200:
 
100
  translated_text = ' '.join(item[0] for item in response.json()[0] if item[0])
101
 
102
  # 3. 따옴표 안의 단어 처리
103
+ # 영어 단어이거나 대문자로 된 단어는 그대로 유지
104
+ if re.match(r'^[A-Z]+$', quoted_word) or re.match(r'^[A-Za-z]+$', quoted_word):
105
  proper_noun = quoted_word.upper()
106
  else: # 한글 단어인 경우
107
  params["q"] = quoted_word
 
112
  proper_noun = quoted_word.upper()
113
 
114
  # 4. 최종 문장 조합
115
+ # XXXXX를 따옴표로 묶은 proper_noun으로 대체
116
+ final_text = translated_text.replace("XXXXX", f"'{proper_noun}'")
117
+
118
+ # 불필요한 대문자 변환 방지
119
+ final_text = re.sub(r'\bNAME\b', 'name', final_text)
120
+
121
+ # 마침표 처리
122
+ final_text = final_text.replace(" .", ".")
123
 
124
  return final_text
125