Skip to content

Instantly share code, notes, and snippets.

@XiaoGeNintendo
Created January 9, 2021 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XiaoGeNintendo/2620e38f7d404e18323e5e7c5be9e7ef to your computer and use it in GitHub Desktop.
Save XiaoGeNintendo/2620e38f7d404e18323e5e7c5be9e7ef to your computer and use it in GitHub Desktop.
(TSRT) Translator for 163
inp=[]
dic=dict()
occur=set()
def levenshteinDistance(s1, s2):
if len(s1) > len(s2):
s1, s2 = s2, s1
distances = range(len(s1) + 1)
for i2, c2 in enumerate(s2):
distances_ = [i2+1]
for i1, c1 in enumerate(s1):
if c1 == c2:
distances_.append(distances[i1])
else:
distances_.append(1 + min((distances[i1], distances[i1 + 1], distances_[-1])))
distances = distances_
return distances[-1]
def lookFor(source):
mn=10**9
mni="?"
for i in dic:
edit=levenshteinDistance(i,source)
if edit<mn:
mni=i
mn=edit
return mni
with open("translate.txt",mode="r",encoding="utf-8") as f:
for i in f.readlines():
if '/' in i:
v=i.split("/")
v[1]=v[1].strip().replace(" "," ").replace(" ","")
v[0]=v[0].strip()
dic[v[1]]=v[0]
print(v[1],"->",v[0])
with open("out.txt",mode="r",encoding="utf-8") as f:
with open("out2.txt",mode="w",encoding="utf-8") as f2:
lst=f.readlines()
# lst.reverse()
for i in lst:
v=i.split("!!!")
source=v[0]
v[0]=v[0].replace(" "," ").replace(" ","").replace("~","~")
# if v[0] in occur:
# print("Occured:",v[0])
# continue
if v[0] in dic:
f2.write(dic[v[0]]+"!!!"+v[1]+"!!!"+v[2])
# print(v[0],"to",dic[v[0]])
else:
val=lookFor(v[0])
f2.write(dic[val]+"⚠(JP:"+source+")!!!"+v[1]+"!!!"+v[2])
print("Failed to translate:"+v[0],"guessed",val)
occur.add(v[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment