Perfect the nscripter parser
This commit is contained in:
parent
2210cc1436
commit
5edd1276d9
1 changed files with 61 additions and 49 deletions
|
|
@ -49,7 +49,7 @@ if 'gpt-3.5' in MODEL:
|
||||||
elif 'gpt-4' in MODEL:
|
elif 'gpt-4' in MODEL:
|
||||||
INPUTAPICOST = .01
|
INPUTAPICOST = .01
|
||||||
OUTPUTAPICOST = .03
|
OUTPUTAPICOST = .03
|
||||||
BATCHSIZE = 10
|
BATCHSIZE = 40
|
||||||
|
|
||||||
def handleNScript(filename, estimate):
|
def handleNScript(filename, estimate):
|
||||||
global ESTIMATE
|
global ESTIMATE
|
||||||
|
|
@ -178,32 +178,35 @@ def translateNScript(data, pbar, totalLines):
|
||||||
speaker = ''
|
speaker = ''
|
||||||
|
|
||||||
# Choices
|
# Choices
|
||||||
matchList = re.findall(r'\[sel.+text="(.+?)".+', data[i])
|
if 'select' in data[i]:
|
||||||
if len(matchList) != 0:
|
matchList = re.findall(r'\"(.*?)\"', data[i])
|
||||||
originalText = matchList[0]
|
if len(matchList) != 0:
|
||||||
if len(textHistory) > 0:
|
originalTextList = matchList
|
||||||
response = translateGPT(matchList[0], 'Keep your translation as brief as possible. Previous text for context: ' + textHistory[len(textHistory)-1] + '\n\nReply in the style of a dialogue option.', False)
|
if len(textHistory) > 0:
|
||||||
else:
|
response = translateGPT(matchList, 'Keep your translation as brief as possible. Previous text for context: ' + textHistory[len(textHistory)-1] + '\n\nReply in the style of a dialogue option.', True)
|
||||||
response = translateGPT(matchList[0], '\n\nReply in the style of a dialogue option.', False)
|
else:
|
||||||
translatedText = response[0]
|
response = translateGPT(matchList, '\n\nReply in the style of a dialogue option.', True)
|
||||||
tokens[0] += response[1][0]
|
translatedTextList = response[0]
|
||||||
tokens[1] += response[1][1]
|
tokens[0] += response[1][0]
|
||||||
|
tokens[1] += response[1][1]
|
||||||
|
|
||||||
# Remove characters that may break scripts
|
for choice in range(len(translatedTextList)):
|
||||||
charList = ['.', '\"', '\\n']
|
translatedText = translatedTextList[choice]
|
||||||
for char in charList:
|
|
||||||
translatedText = translatedText.replace(char, '')
|
# Remove characters that may break scripts
|
||||||
|
charList = ['.', '\"', '\\n']
|
||||||
|
for char in charList:
|
||||||
|
translatedText = translatedText.replace(char, '')
|
||||||
|
|
||||||
# Escape all '
|
# Escape all '
|
||||||
translatedText = translatedText.replace('\\', '')
|
translatedText = translatedText.replace('\\', '')
|
||||||
# translatedText = translatedText.replace("'", "\\\'")
|
|
||||||
|
|
||||||
# Set Data
|
# Set Data
|
||||||
translatedText = data[i].replace(originalText, translatedText)
|
translatedText = data[i].replace(originalTextList[choice], translatedText)
|
||||||
data[i] = translatedText
|
data[i] = translatedText
|
||||||
|
|
||||||
# Lines
|
# Lines
|
||||||
matchList = re.findall(r'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >].*', data[i])
|
matchList = re.findall(r'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >()].*', data[i])
|
||||||
if len(matchList) > 0:
|
if len(matchList) > 0:
|
||||||
currentGroup.append(matchList[0])
|
currentGroup.append(matchList[0])
|
||||||
if len(data) > i+1:
|
if len(data) > i+1:
|
||||||
|
|
@ -213,16 +216,16 @@ def translateNScript(data, pbar, totalLines):
|
||||||
data[i] = '\d\n'
|
data[i] = '\d\n'
|
||||||
pbar.update(1)
|
pbar.update(1)
|
||||||
i += 1
|
i += 1
|
||||||
matchList = re.findall(r'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >].*', data[i])
|
matchList = re.findall(r'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >()].*', data[i])
|
||||||
if len(matchList) > 0:
|
if len(matchList) > 0:
|
||||||
currentGroup.append(matchList[0])
|
currentGroup.append(matchList[0])
|
||||||
else:
|
else:
|
||||||
while ' ' in data[i+1][0] or '"' in data[i+1]:
|
while ' ' in data[i+1][0] or '"' in data[i+1] or ')' in data[i+1] or ')' in data[i+1]:
|
||||||
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'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >].*', data[i])
|
matchList = re.findall(r'^[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9「」 >()].*', data[i])
|
||||||
if len(matchList) > 0:
|
if len(matchList) > 0:
|
||||||
currentGroup.append(matchList[0])
|
currentGroup.append(matchList[0])
|
||||||
|
|
||||||
|
|
@ -234,6 +237,7 @@ def translateNScript(data, pbar, totalLines):
|
||||||
# Remove any textwrap
|
# Remove any textwrap
|
||||||
if FIXTEXTWRAP == True:
|
if FIXTEXTWRAP == True:
|
||||||
finalJAString = finalJAString.replace('>', '')
|
finalJAString = finalJAString.replace('>', '')
|
||||||
|
finalJAString = finalJAString.replace('\\', ' ')
|
||||||
|
|
||||||
# Remove Extra Stuff bad for translation.
|
# Remove Extra Stuff bad for translation.
|
||||||
finalJAString = finalJAString.replace('゙', '')
|
finalJAString = finalJAString.replace('゙', '')
|
||||||
|
|
@ -304,13 +308,22 @@ def translateNScript(data, pbar, totalLines):
|
||||||
|
|
||||||
# Set Text
|
# Set Text
|
||||||
data[i] = '\d\n'
|
data[i] = '\d\n'
|
||||||
|
counter = 0
|
||||||
for line in textList:
|
for line in textList:
|
||||||
# Wordwrap Text
|
# Wordwrap Text
|
||||||
line = textwrap.fill(line, width=WIDTH)
|
line = textwrap.fill(line, width=WIDTH)
|
||||||
|
|
||||||
# Set
|
# Set
|
||||||
data.insert(i, '>' + line.strip() + '\n')
|
data.insert(i, '>' + line.strip() + '\n')
|
||||||
|
counter += 1
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
|
# Go to new window if too long
|
||||||
|
if counter >= 4:
|
||||||
|
data[i-1] = data[i-1].replace('\n', '\\\n')
|
||||||
|
counter = 0
|
||||||
|
if '\\' not in data[i-1]:
|
||||||
|
data[i-1] = data[i-1].replace('\n', '\\\n')
|
||||||
translatedBatch.pop(0)
|
translatedBatch.pop(0)
|
||||||
speaker = ''
|
speaker = ''
|
||||||
currentGroup = []
|
currentGroup = []
|
||||||
|
|
@ -354,24 +367,27 @@ def translateNScript(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 ['Akira', [0,0]]
|
|
||||||
case '累':
|
|
||||||
return ['Rui', [0,0]]
|
return ['Rui', [0,0]]
|
||||||
case '梨里':
|
case 'チュベロス':
|
||||||
return ['Riri', [0,0]]
|
return ['Tuberose', [0,0]]
|
||||||
case '純':
|
case '':
|
||||||
return ['Jun', [0,0]]
|
return ['', [0,0]]
|
||||||
case '美鈴':
|
|
||||||
return ['Misuzu', [0,0]]
|
|
||||||
case '須田':
|
|
||||||
return ['Suda', [0,0]]
|
|
||||||
case '高橋':
|
|
||||||
return ['Takahashi', [0,0]]
|
|
||||||
case '勇二':
|
|
||||||
return ['Yuuji', [0,0]]
|
|
||||||
case _:
|
case _:
|
||||||
return translateGPT(speaker, 'Reply with only the '+ LANGUAGE +' translation of the NPC name.', False)
|
# Store Speaker
|
||||||
|
if speaker not in str(NAMESLIST):
|
||||||
|
response = translateGPT(speaker, 'Reply with only the '+ LANGUAGE +' translation of the NPC name.', False)
|
||||||
|
response[0] = response[0].title()
|
||||||
|
speakerList = [speaker, response[0]]
|
||||||
|
NAMESLIST.append(speakerList)
|
||||||
|
return response
|
||||||
|
# Find Speaker
|
||||||
|
else:
|
||||||
|
for i in range(len(NAMESLIST)):
|
||||||
|
if speaker == NAMESLIST[i][0]:
|
||||||
|
return [NAMESLIST[i][1],[0,0]]
|
||||||
|
|
||||||
|
return [speaker,[0,0]]
|
||||||
|
|
||||||
def subVars(jaString):
|
def subVars(jaString):
|
||||||
jaString = jaString.replace('\u3000', ' ')
|
jaString = jaString.replace('\u3000', ' ')
|
||||||
|
|
@ -494,14 +510,10 @@ def batchList(input_list, batch_size):
|
||||||
|
|
||||||
def createContext(fullPromptFlag, subbedT):
|
def createContext(fullPromptFlag, subbedT):
|
||||||
characters = 'Game Characters:\n\
|
characters = 'Game Characters:\n\
|
||||||
渋江 央 (Shibue Akira) - Male\n\
|
水原 雪 (Minahara Yuki) - Female\n\
|
||||||
蘆名 累 (Ashina Rui) - Female\n\
|
黒服の男 (Man in Black) - Male\n\
|
||||||
清原 梨里 (Kiyohara Riri) - Female\n\
|
駿河 京也 (Suruga Kyouya) - Male\n\
|
||||||
五十嵐 純 (Igarashi Jun) - Female\n\
|
壱型02 (Type 02) - Monster\n\
|
||||||
子野日 美鈴 (Nenohi Misuzu) - Female\n\
|
|
||||||
須田 (Suda) - Male\n\
|
|
||||||
高橋 (Takahashi) - Female\n\
|
|
||||||
勇二 (Yuuji) - Male\n\
|
|
||||||
'
|
'
|
||||||
|
|
||||||
system = PROMPT + VOCAB if fullPromptFlag else \
|
system = PROMPT + VOCAB if fullPromptFlag else \
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue