Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
Limour's picture
Upload 12 files
6b4490e verified
raw
history blame
4.23 kB
def get_all_files_in_directory(directory, ext=''):
import os
import re
custom_sort_key_re = re.compile('([0-9]+)')
def custom_sort_key(s):
# 将字符串中的数字部分转换为整数,然后进行排序
return [int(x) if x.isdigit() else x for x in custom_sort_key_re.split(s)]
all_files = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(ext):
file_path = os.path.join(root, file)
all_files.append(file_path)
return sorted(all_files, key=custom_sort_key)
def clearT():
import unicodedata
from opencc import OpenCC
def full2half(input_str):
return ''.join([unicodedata.normalize('NFKC', char) for char in input_str])
cc = OpenCC('t2s') # 't2s'表示繁体转简体
def _clearT(s):
s = cc.convert(full2half(s))
return s.lstrip('n').strip().strip(r'\n').replace('\n', '\\n')
return _clearT
clearT = clearT()
# =================
a = get_all_files_in_directory(r'E:\tmp\ISLAND\cst', ext='.cstl')
b = r'D:\datasets\tmp'
# =================
sc = {}
_n = {
"旁白": "旁白",
"镇长": "镇长",
"声音": "声音",
"?": "?",
"少女": "少女",
"琳": "琳",
"女子": "女子",
"切那": "切那",
"玖音": "玖音",
"女孩": "女孩",
"纱罗": "纱罗",
"夏莲": "夏莲",
"巡警": "巡警",
"看守": "看守",
"桃香": "桃香",
"凛音": "凛音",
"守春": "守春",
"女性": "女性",
"切那&夏莲": "切那&夏莲",
"Setsuna": "Setsuna",
"Linne": "Linne",
"Karen": "Karen",
"Sarah": "Sarah",
"熊孩子A": "熊孩子A",
"熊孩子B": "熊孩子B",
"熊孩子C": "熊孩子C",
"熊孩子们": "熊孩子们",
"男性": "男性",
"女学生": "女学生",
"老奶奶": "老奶奶",
"夏莲・纱罗": "夏莲&纱罗",
"切那&凛音": "切那&凛音",
"船长": "船长",
"  ": "――",
"雨兰": "雨兰",
"凛音&切那": "凛音&切那",
"老人": "老人",
"森须": "森须",
"切那・纱罗": "切那&纱罗",
"鱼店老板": "鱼店老板",
"切那&纱罗": "切那&纱罗",
"??": "?",
"???": "?",
"万??": "万??",
"万里?": "万里?",
"万里爱": "万里爱",
"Nehan": "Nehan",
"凛音・纱罗": "凛音&纱罗",
"玖音?": "玖音?",
"雨兰?": "雨兰?",
"玖音&雨兰": "玖音&雨兰",
"夏莲&纱罗": "夏莲&纱罗",
"――": "――", # 三千界切那 但是此时还不记得自己的名字
"孩童": "孩童",
"头盖骨?": "头盖骨?",
"男孩": "男孩",
"Peach": "Peach",
"二人": "二人",
"男性1": "男性1",
"男性2": "男性2",
"男性3": "男性3",
"老人1": "老人1",
"老人2": "老人2",
"老人3": "老人3",
"卫兵": "卫兵"
}
# =================
def spStrip(s :str):
retn = ''
_i = -1
while _i < len(s) - 1:
_i += 1
char = s[_i]
if char == '\\':
_i += 2
elif char == '[':
_d = True
while _i < len(s) - 1:
_i += 1
char = s[_i]
if char == ']':
break
if char == '/':
_d = False
if _d:
retn += char
else:
retn += char
return retn
# =================
from cstl2txt import getTxt
for path in a:
name = path[path.rindex('\\'):]
name = name[:4]
if name not in sc:
sc[name] = []
print(name)
# =================
data = getTxt(path)
w_i = -1
while w_i < len(data) - 1:
w_i += 1
n = data[w_i]
if not n:
n = '旁白'
w_i += 1
d = spStrip(data[w_i])
w_i += 2 # skip jp
# print(n, d)
if n in _n:
n = _n[n]
else:
_n[n] = clearT(n)
if d:
sc[name].append(n + ':' + d)
# =================
for k, v in sc.items():
with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
f.write('\n'.join(v))
# =================
import json
tmp = json.dumps(_n, ensure_ascii=False, indent=2)