Slight edit to regex

This commit is contained in:
Dazed 2023-12-30 23:20:48 -06:00
parent fec7f8fa8e
commit a8b5cf5fa8
5 changed files with 38 additions and 46 deletions

View file

@ -472,7 +472,7 @@ def cleanTranslatedText(translatedText, varResponse):
return [line for line in translatedText.split('\\n') if line] return [line for line in translatedText.split('\\n') if line]
def extractTranslation(translatedTextList, is_list): def extractTranslation(translatedTextList, is_list):
pattern = r'<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</Line\d+>' pattern = r'<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</?Line\d+>'
# If it's a batch (i.e., list), extract with tags; otherwise, return the single item. # If it's a batch (i.e., list), extract with tags; otherwise, return the single item.
if is_list: if is_list:
return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)] return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)]

View file

@ -445,7 +445,7 @@ def cleanTranslatedText(translatedText, varResponse):
return [line for line in translatedText.split('\\n') if line] return [line for line in translatedText.split('\\n') if line]
def extractTranslation(translatedTextList, is_list): def extractTranslation(translatedTextList, is_list):
pattern = r'<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</Line\d+>' pattern = r'<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</?Line\d+>'
# If it's a batch (i.e., list), extract with tags; otherwise, return the single item. # If it's a batch (i.e., list), extract with tags; otherwise, return the single item.
if is_list: if is_list:
return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)] return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)]

View file

@ -575,7 +575,7 @@ def cleanTranslatedText(translatedText, varResponse):
return [line for line in translatedText.split('\\n') if line] return [line for line in translatedText.split('\\n') if line]
def extractTranslation(translatedTextList, is_list): def extractTranslation(translatedTextList, is_list):
pattern = r'<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</Line\d+>' pattern = r'<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</?Line\d+>'
# If it's a batch (i.e., list), extract with tags; otherwise, return the single item. # If it's a batch (i.e., list), extract with tags; otherwise, return the single item.
if is_list: if is_list:
return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)] return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)]

View file

@ -1933,7 +1933,7 @@ def cleanTranslatedText(translatedText, varResponse):
return [line for line in translatedText.split('\n') if line] return [line for line in translatedText.split('\n') if line]
def extractTranslation(translatedTextList, is_list): def extractTranslation(translatedTextList, is_list):
pattern = r'<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</Line\d+>' pattern = r'<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</?Line\d+>'
# If it's a batch (i.e., list), extract with tags; otherwise, return the single item. # If it's a batch (i.e., list), extract with tags; otherwise, return the single item.
if is_list: if is_list:
return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)] return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)]

View file

@ -76,7 +76,7 @@ def handleTyrano(filename, estimate):
else: else:
try: try:
with open('translated/' + filename, 'w', encoding='shift_jis', errors='ignore') as outFile: with open('translated/' + filename, 'w', encoding='utf8', errors='ignore') as outFile:
start = time.time() start = time.time()
translatedData = openFiles(filename) translatedData = openFiles(filename)
@ -118,7 +118,7 @@ def getResultString(translatedData, translationTime, filename):
errorString + Fore.RESET errorString + Fore.RESET
def openFiles(filename): def openFiles(filename):
with open('files/' + filename, 'r', encoding='cp932') as readFile: with open('files/' + filename, 'r', encoding='utf8') as readFile:
translatedData = parseTyrano(readFile, filename) translatedData = parseTyrano(readFile, filename)
# Delete lines marked for deletion # Delete lines marked for deletion
@ -165,14 +165,14 @@ def translateTyrano(data, pbar, totalLines):
while i < len(data): while i < len(data):
# Speaker # Speaker
if '[ns]' in data[i]: if '#' in data[i]:
matchList = re.findall(r'\[ns\](.+?)\[', data[i]) matchList = re.findall(r'#【(.+)】', data[i])
if len(matchList) != 0: if len(matchList) != 0:
response = getSpeaker(matchList[0]) response = getSpeaker(matchList[0])
speaker = response[0] speaker = response[0]
tokens[0] += response[1][0] tokens[0] += response[1][0]
tokens[1] += response[1][1] tokens[1] += response[1][1]
data[i] = '[ns]' + speaker + '[nse]\n' data[i] = '#【' + speaker + '\n'
else: else:
speaker = '' speaker = ''
@ -205,22 +205,19 @@ def translateTyrano(data, pbar, totalLines):
# Lines # Lines
matchList = re.findall(r'(.+?)\[[rpcms]+\]$', data[i]) matchList = re.findall(r'(.+?)\[[rpcms]+\]$', data[i])
if len(matchList) > 0: if len(matchList) > 0:
# Skip if comment
if matchList[0][0] == ';':
continue
# Grab Text
currentGroup.append(matchList[0]) currentGroup.append(matchList[0])
if len(data) > i+1: if len(data) > i+1:
while '[r]' in data[i+1]: while re.search(r'(.+?)\[[rpcms]+\]$', data[i+1]) is not None:
if insertBool is True: if insertBool is True:
data[i] = '\d\n' data[i] = '\d\n'
pbar.update(1) pbar.update(1)
i += 1 i += 1
matchList = re.findall(r'(.+?)\[r\]', data[i]) matchList = re.findall(r'(.+?)\[[rpcms]+\]$', data[i])
if len(matchList) > 0:
currentGroup.append(matchList[0])
while '[pcms]' in data[i+1]:
if insertBool is True:
data[i] = '\d\n'
pbar.update(1)
i += 1
matchList = re.findall(r'(.+?)\[pcms\]', data[i])
if len(matchList) > 0: if len(matchList) > 0:
currentGroup.append(matchList[0]) currentGroup.append(matchList[0])
# Join up 401 groups for better translation. # Join up 401 groups for better translation.
@ -310,7 +307,7 @@ def translateTyrano(data, pbar, totalLines):
# Set # Set
data.insert(i, line.strip() + '[r]\n') data.insert(i, line.strip() + '[r]\n')
i+=1 i+=1
data[i-1] = data[i-1].replace('[r]', '[pcms]') data[i-1] = data[i-1].replace('[r]', '[p]')
translatedBatch.pop(0) translatedBatch.pop(0)
speaker = '' speaker = ''
currentGroup = [] currentGroup = []
@ -354,20 +351,20 @@ def translateTyrano(data, pbar, totalLines):
# Save some money and enter the character before translation # Save some money and enter the character before translation
def getSpeaker(speaker): def getSpeaker(speaker):
match speaker: match speaker:
case '': case '':
return ['Makoto', [0,0]] return ['Hitomi', [0,0]]
case '夏都': case 'アイ ':
return ['Natsu', [0,0]] return ['Ai', [0,0]]
case '宗一郎': case 'リン':
return ['Souichirou', [0,0]] return ['Rin', [0,0]]
case '彩月': case '小虎':
return ['Satsuki', [0,0]] return ['Kotora', [0,0]]
case '茜梨': case '玫瑰 ':
return ['Akari', [0,0]] return ['Meigui', [0,0]]
case 'ポホヨネン': case '':
return ['Pohjonen', [0,0]] return ['So', [0,0]]
case '荒井': case '葛生':
return ['Arai', [0,0]] return ['Kuzu', [0,0]]
case '愛梨': case '愛梨':
return ['Airi', [0,0]] return ['Airi', [0,0]]
case '朋美': case '朋美':
@ -512,17 +509,12 @@ def batchList(input_list, batch_size):
def createContext(fullPromptFlag, subbedT): def createContext(fullPromptFlag, subbedT):
characters = 'Game Characters:\n\ characters = 'Game Characters:\n\
中澤 (Nakazawa Makoto) - Male\n\ (Hitomi) - Female\n\
日向 夏都 (Hyuuga Natsu) - Female\n\ リン (Rin) - Female\n\
出渕 宗一郎 (Izubuchi Souichirou) - Male\n\ アイ (Ai) - Female\n\
彩月 (Minami Satsuki) - Female\n\ 玫瑰 (Meigui) - Male\n\
越智 茜梨 (Ochi Akari) - Female\n\ (So) - Male\n\
ターヤ ポホヨネン (Tarja Pohjonen) - Female\n\ 小虎 (Kotora) - Female\n\
マルガリータ バスクェス 穂村 (Margarita Vasquez Homura) - Female\n\
花沢 愛梨 (Hanazawa Airi) - Female\n\
五十嵐 朋美 (Igarashi Tomomi) - Female\n\
前田 美沙緒 (Maeda Misao) - Female\n\
村上 (Murakami Sato) - Female\n\
' '
system = PROMPT if fullPromptFlag else \ system = PROMPT if fullPromptFlag else \
@ -575,7 +567,7 @@ def cleanTranslatedText(translatedText, varResponse):
return [line for line in translatedText.split('\\n') if line] return [line for line in translatedText.split('\\n') if line]
def extractTranslation(translatedTextList, is_list): def extractTranslation(translatedTextList, is_list):
pattern = r'<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</Line\d+>' pattern = r'<Line(\d+)>[\\]*`?(.*?)[\\]*?`?</?Line\d+>'
# If it's a batch (i.e., list), extract with tags; otherwise, return the single item. # If it's a batch (i.e., list), extract with tags; otherwise, return the single item.
if is_list: if is_list:
return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)] return [re.findall(pattern, line)[0][1] for line in translatedTextList if re.search(pattern, line)]