Add choices to kirikiri

This commit is contained in:
DazedAnon 2024-10-23 07:47:51 -05:00
parent 90f0ee5d25
commit 43019917b9
2 changed files with 84 additions and 106 deletions

View file

@ -49,6 +49,11 @@ BAR_FORMAT = "{l_bar}{bar:10}{r_bar}{bar:-10b}"
POSITION = 0 POSITION = 0
LEAVE = False LEAVE = False
# Flags
SPEAKERS = False
CHOICES = True
DIALOGUE = False
# Pricing - Depends on the model https://openai.com/pricing # Pricing - Depends on the model https://openai.com/pricing
# Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request # Batch Size - GPT 3.5 Struggles past 15 lines per request. GPT4 struggles past 50 lines per request
# If you are getting a MISMATCH LENGTH error, lower the batch size. # If you are getting a MISMATCH LENGTH error, lower the batch size.
@ -159,14 +164,6 @@ def getResultString(translatedData, translationTime, filename):
def openFiles(filename): def openFiles(filename):
with open("files/" + filename, "r", encoding="utf16") as readFile: with open("files/" + filename, "r", encoding="utf16") as readFile:
translatedData = parseKiriKiri(readFile, filename) translatedData = parseKiriKiri(readFile, filename)
# Delete lines marked for deletion
finalData = []
for line in translatedData[0]:
if line != "\\d\n":
finalData.append(line)
translatedData[0] = finalData
return translatedData return translatedData
@ -191,8 +188,16 @@ def parseKiriKiri(readFile, filename):
return [data, totalTokens, None] return [data, totalTokens, None]
def translateKiriKiri(data, pbar, filename, translatedList): def translateKiriKiri(data, pbar, filename, jobList):
stringList = [] # Check Job Data
if len(jobList) > 0:
stringList = jobList[0]
choiceList = jobList[1]
setData = True
else:
stringList = []
choiceList = []
setData = False
tokens = [0, 0] tokens = [0, 0]
speaker = "" speaker = ""
global LOCK, ESTIMATE global LOCK, ESTIMATE
@ -200,14 +205,15 @@ def translateKiriKiri(data, pbar, filename, translatedList):
# Regex # Regex
speakerRegex = r'【(.*)】\[CR\]' speakerRegex = r'【(.*)】\[CR\]'
dialogueRegex = r'^\[text\](.*).*\[KeyWait\]|\[v\](.*)\[\/v\].*\[KeyWait\]' dialogueRegex = r'^\[text\](.*).*\[KeyWait\]|\[\w+\](.*)\[\/\w+\].*\[KeyWait\]'
furiganaRegex = r'(\[eruby\sstr="(.*?)"\stext.*?\])' furiganaRegex = r'(\[eruby\sstr="(.*?)"\stext.*?\])'
choicesRegex = r"^\s*\[button\d\sclickse=sys_decide.*text='(.*?)'.*"
while i < len(data): while i < len(data):
speaker = "" speaker = ""
# Speaker # Speaker
match = re.search(speakerRegex, data[i]) match = re.search(speakerRegex, data[i])
if match: if match and SPEAKERS:
speakerJA = match.group(1) speakerJA = match.group(1)
response = getSpeaker(speakerJA) response = getSpeaker(speakerJA)
speaker = response[0] speaker = response[0]
@ -216,14 +222,35 @@ def translateKiriKiri(data, pbar, filename, translatedList):
data[i] = data[i].replace(speakerJA, speaker) data[i] = data[i].replace(speakerJA, speaker)
i += 1 i += 1
# Choices
match = re.search(choicesRegex, data[i])
if match and CHOICES:
jaString = match.group(1)
# Pass 1
if not setData:
choiceList.append(jaString)
# Pass 2
else:
# Grab and Pop and Set
translatedText = choiceList[0]
choiceList.pop(0)
# Replace Quotes
data[i] = data[i].replace("'", '"')
translatedText = translatedText.replace('"', "'")
data[i] = data[i].replace(jaString, translatedText)
# Dialogue # Dialogue
match = re.search(dialogueRegex, data[i]) match = re.search(dialogueRegex, data[i])
if match: if match and DIALOGUE:
jaString = match.group(1) jaString = match.group(1)
if not jaString: if not jaString:
jaString = match.group(2) jaString = match.group(2)
# Pass 1 # Pass 1
if translatedList == []: if not setData:
# Remove any textwrap # Remove any textwrap
jaString = jaString.replace("[r]", " ") jaString = jaString.replace("[r]", " ")
@ -242,12 +269,8 @@ def translateKiriKiri(data, pbar, filename, translatedList):
# Pass 2 # Pass 2
else: else:
# Grab and Pop # Grab and Pop
translatedText = translatedList[0] translatedText = stringList[0]
translatedList.pop(0) stringList.pop(0)
# Set to None if empty list
if len(translatedList) <= 0:
translatedList = None
# Remove Speaker # Remove Speaker
translatedText = translatedText.replace(f"[{speaker}]: ", "") translatedText = translatedText.replace(f"[{speaker}]: ", "")
@ -263,6 +286,10 @@ def translateKiriKiri(data, pbar, filename, translatedList):
i += 1 i += 1
# EOF # EOF
stringListTL = []
choiceListTL = []
# Dialogue
if len(stringList) > 0: if len(stringList) > 0:
# Set Progress # Set Progress
pbar.total = len(stringList) pbar.total = len(stringList)
@ -276,17 +303,41 @@ def translateKiriKiri(data, pbar, filename, translatedList):
) )
tokens[0] += response[1][0] tokens[0] += response[1][0]
tokens[1] += response[1][1] tokens[1] += response[1][1]
translatedList = response[0] stringListTL = response[0]
# Set Strings # Validate
if len(stringList) == len(translatedList): if len(stringList) != len(stringListTL):
translateKiriKiri(data, pbar, filename, translatedList)
# Mismatch
else:
with LOCK: with LOCK:
if filename not in MISMATCH: if filename not in MISMATCH:
MISMATCH.append(filename) MISMATCH.append(filename)
stringListTL = stringList
# Choices
if len(choiceList) > 0:
# Set Progress
pbar.total = len(choiceList)
pbar.refresh()
# Translate
response = translateGPT(
choiceList,
"",
True,
)
tokens[0] += response[1][0]
tokens[1] += response[1][1]
choiceListTL = response[0]
# Validate
if len(choiceList) != len(choiceListTL):
with LOCK:
if filename not in MISMATCH:
MISMATCH.append(filename)
choiceListTL = choiceList
# Proceed to Pass 2
translateKiriKiri(data, pbar, filename, [stringListTL, choiceListTL])
return tokens return tokens

View file

@ -1,43 +1,11 @@
Here are some vocabulary and terms so that you know the proper spelling and translation. Here are some vocabulary and terms so that you know the proper spelling and translation.
``` ```
# Game Characters # Game Characters
コサギ (Kosagi) - Male 御木原菜月 (Mikihara Natsuki) - Female
ヒサメ (Hisame) - Female エクセルシフォン (Excel Chiffon) - Female
モミジ (Momiji) - Female 如月深冬 (Kisaragi Mifuyu) - Female
ミズキ (Mizuki) - Female エクセルショコラ (Excel Chocolat) - Female
ホノカ (Honoka) - Female レヴィエラ (Reviella) - Female
チヅル (Chizuru) - Female
リュウゲン (Ryugen) - Male
ゴサク (Gosaku) - Male
トウジ (Touji) - Male
シグレ (Shigure) - Female
カツラギ (Katsuragi) - Male
リュウヤ (Ryuya) - Male
ヨシモト (Yoshimoto) - Male
ヤエ (Yae) - Female
シラツユ (Shiratsuyu) - Female
ジンスケ (Jinsuke) - Male
ハクビ (Hakubi) - Male
ゲンセイ (Gensei) - Male
レイゼイ (Reizei) - Male
ソラ (Sora) - Male
テッシュウ (Tesshu) - Male
ゲンサイ (Gensai) - Female
タネ (Tane) - Female
ドウキュウ (Doukyu) - Male
コロク (Koroku) - Male
ヤタロウ (Yataro) - Male
ドウマン (Douman) - Male
ブンキチ (Bunkichi) - Male
キッペイ (Kippei) - Male
シンパチ (Shinpachi) - Male
アザミ (Azami) - Female
セキジ (Sekiji) - Male
システィナ (Sistina) - Female
バサラ (Basara) - Male
ジカイ (Jikai) - Male
レンゲ (Renge) - Female
タサブロウ (Tasaburou) - Male
# Lewd Terms # Lewd Terms
マンコ (pussy) マンコ (pussy)
@ -111,47 +79,6 @@ ME 音量 (ME Volume)
w ((lol)) w ((lol))
巫女 (Shrine Maiden) 巫女 (Shrine Maiden)
コイツ (this bastard) コイツ (this bastard)
エルゴネア (Ergonia)
# Names
オサンギツネ (Osangitsune)
クウコ (Kuuko)
タマモノマエ (Tamamo-no-Mae)
タタリモッケ (Tatarimokke)
ヤタガラス (Yatagarasu)
ライジュウ (Raijuu)
ヌエ (Nue)
ゴトクネコ (Gotokuneko)
カジガカカ (Kajigakaka)
バッキ (Bakki)
ヒデリガミ (Hiderigami)
ナルカミ (Narukami)
マガツヒノカミ (Magatsuhinokami)
アマノジャク (Amanojaku)
ウラ (Ura)
シュテンドウジ (Shuten Douji)
ガワッパ (Gawappa)
スイコ (Suiko)
ユキンコ (Yukinko)
ツララオンナ (Tsurara Onna)
ワニザメ (Bull Shark)
アマビエ (Amabie)
オトロシ (Otoroshi)
アカシタサマ (Akashita-sama)
ノビアガリ (Nobiagari)
タカオンナ (Takaonna)
ヤシャ (Yasha)
ラセツ (Rasetsu)
オオタケマル (Ootakemaru)
ジュボッコ (Jubokko)
ホウコウ (Houkoh)
ツチグモ (Tsuchigumo)
ジョロウグモ (Jorogumo)
ムジナ (Mujina)
フクロサゲ (Fukurosage)
ワイラ (Waira)
サンジャクボウ (Sanjakubou)
セキヨウ (Sekiyou)
ウンガイキョウ (Ungai-kyo)
リュウヤ (Ryuya)
``` ```