生命的备件
Browse files
v-corpus-zh/AKABEiSOFT2/生命的备件/0.txt.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a24f24c8f9b654fbdc44399eda08ed6ae4c184b06bfce8eed0f1faa341eabef0
|
3 |
+
size 344630
|
v-corpus-zh/AKABEiSOFT2/生命的备件/生命的备件_ks.py
ADDED
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def get_all_files_in_directory(directory, ext=''):
|
2 |
+
import os
|
3 |
+
import re
|
4 |
+
custom_sort_key_re = re.compile('([0-9]+)')
|
5 |
+
|
6 |
+
def custom_sort_key(s):
|
7 |
+
# 将字符串中的数字部分转换为整数,然后进行排序
|
8 |
+
return [int(x) if x.isdigit() else x for x in custom_sort_key_re.split(s)]
|
9 |
+
|
10 |
+
all_files = []
|
11 |
+
for root, dirs, files in os.walk(directory):
|
12 |
+
for file in files:
|
13 |
+
if file.endswith(ext):
|
14 |
+
file_path = os.path.join(root, file)
|
15 |
+
all_files.append(file_path)
|
16 |
+
return sorted(all_files, key=custom_sort_key)
|
17 |
+
|
18 |
+
|
19 |
+
def clearT():
|
20 |
+
import unicodedata
|
21 |
+
from opencc import OpenCC
|
22 |
+
|
23 |
+
def full2half(input_str):
|
24 |
+
return ''.join([unicodedata.normalize('NFKC', char) for char in input_str])
|
25 |
+
|
26 |
+
cc = OpenCC('t2s') # 't2s'表示繁体转简体
|
27 |
+
|
28 |
+
def _clearT(s):
|
29 |
+
s = cc.convert(full2half(s))
|
30 |
+
return s.strip().strip(r'\n').replace('\n', '\\n')
|
31 |
+
|
32 |
+
return _clearT
|
33 |
+
|
34 |
+
|
35 |
+
clearT = clearT()
|
36 |
+
|
37 |
+
|
38 |
+
def startsWithAny(s: str, keys):
|
39 |
+
for x in keys:
|
40 |
+
if s.startswith(x):
|
41 |
+
return x
|
42 |
+
else:
|
43 |
+
return False
|
44 |
+
|
45 |
+
|
46 |
+
def endsWithAny(s: str, keys):
|
47 |
+
for x in keys:
|
48 |
+
if s.endswith(x):
|
49 |
+
return x
|
50 |
+
else:
|
51 |
+
return False
|
52 |
+
|
53 |
+
|
54 |
+
def startsWithAlnum(s: str, _chrs):
|
55 |
+
retn = ''
|
56 |
+
for char in s:
|
57 |
+
if (char.isalnum()) or (char in _chrs):
|
58 |
+
retn += char
|
59 |
+
else:
|
60 |
+
break
|
61 |
+
return retn
|
62 |
+
|
63 |
+
|
64 |
+
def startsWithCmd(s: str, _chrs=None):
|
65 |
+
if _chrs is None:
|
66 |
+
_chrs = {'_', '@'}
|
67 |
+
cmd = startsWithAlnum(s, _chrs)
|
68 |
+
if cmd:
|
69 |
+
return s.startswith(cmd + ' ')
|
70 |
+
else:
|
71 |
+
return False
|
72 |
+
|
73 |
+
|
74 |
+
import re
|
75 |
+
|
76 |
+
reg_removeWait = re.compile(r'\[.+?]')
|
77 |
+
|
78 |
+
|
79 |
+
def removeWait(_line):
|
80 |
+
_tmp = reg_removeWait.sub('', _line)
|
81 |
+
if _tmp:
|
82 |
+
return _tmp
|
83 |
+
else:
|
84 |
+
return _line
|
85 |
+
|
86 |
+
|
87 |
+
def getCmdArgs(_cmd):
|
88 |
+
_args = ['']
|
89 |
+
_i = -1
|
90 |
+
_inQuota = ''
|
91 |
+
while _i < len(_cmd) - 1:
|
92 |
+
_i += 1
|
93 |
+
char = _cmd[_i]
|
94 |
+
if _inQuota:
|
95 |
+
_args[-1] += char
|
96 |
+
if char == _inQuota:
|
97 |
+
_inQuota = ''
|
98 |
+
elif char == '\\':
|
99 |
+
_i += 1
|
100 |
+
char = _cmd[_i]
|
101 |
+
_args[-1] += char
|
102 |
+
else:
|
103 |
+
pass
|
104 |
+
else:
|
105 |
+
if char == ' ':
|
106 |
+
_args.append('')
|
107 |
+
while _i < len(_cmd) - 1:
|
108 |
+
_i += 1
|
109 |
+
char = _cmd[_i]
|
110 |
+
if char != ' ':
|
111 |
+
_i -= 1
|
112 |
+
break
|
113 |
+
continue
|
114 |
+
elif char in {'"', "'"}:
|
115 |
+
_inQuota = char
|
116 |
+
else:
|
117 |
+
pass
|
118 |
+
_args[-1] += char
|
119 |
+
continue
|
120 |
+
return _args
|
121 |
+
|
122 |
+
|
123 |
+
def args2map(_args):
|
124 |
+
retn = {}
|
125 |
+
for _i in range(1, len(_args)):
|
126 |
+
_arg = _args[_i]
|
127 |
+
if '=' not in _arg:
|
128 |
+
if '=' in _arg:
|
129 |
+
_arg = _arg.replace('=', '=')
|
130 |
+
else:
|
131 |
+
continue
|
132 |
+
_idx = _arg.index('=')
|
133 |
+
_k = _arg[:_idx]
|
134 |
+
if '"' in _k or "'" in _k:
|
135 |
+
continue
|
136 |
+
_v = _arg[_idx + 1:]
|
137 |
+
if _v.startswith('"') or _v.startswith("'"):
|
138 |
+
_v = _v[1:len(_v) - 1]
|
139 |
+
retn[_k] = _v
|
140 |
+
return retn
|
141 |
+
|
142 |
+
|
143 |
+
# =================
|
144 |
+
|
145 |
+
a = get_all_files_in_directory(r'E:\tmp\生命的备件\ks', ext='.ks')
|
146 |
+
b = r'D:\datasets\tmp'
|
147 |
+
|
148 |
+
# =================
|
149 |
+
|
150 |
+
sc = {}
|
151 |
+
|
152 |
+
_n = {
|
153 |
+
"虎太郎": "虎太郎",
|
154 |
+
"竜次": "龙次",
|
155 |
+
"恵璃": "恵璃",
|
156 |
+
"大宮": "大宫",
|
157 |
+
"小金井": "小金井",
|
158 |
+
"璃亜": "璃亚",
|
159 |
+
"恭也": "恭也",
|
160 |
+
"母": "母",
|
161 |
+
"通行人": "路人",
|
162 |
+
"OL": "OL",
|
163 |
+
"友里恵": "友里恵",
|
164 |
+
"晴信": "晴信",
|
165 |
+
"恵璃&璃亜": "恵璃&璃亚",
|
166 |
+
"露天商": "露天商",
|
167 |
+
"千秋": "千秋",
|
168 |
+
"千秋の恋人": "千秋的恋人",
|
169 |
+
"医師": "医师",
|
170 |
+
"竜次\"": "龙次"
|
171 |
+
}
|
172 |
+
|
173 |
+
# =================
|
174 |
+
for path in a:
|
175 |
+
name = path[path.rindex('\\'):]
|
176 |
+
name = '0'
|
177 |
+
if name not in sc:
|
178 |
+
sc[name] = []
|
179 |
+
print(name)
|
180 |
+
# =================
|
181 |
+
|
182 |
+
with open(path, 'r', encoding='utf-16-le') as f:
|
183 |
+
data = list(filter(lambda x: x and (not x.startswith(';')),
|
184 |
+
(x.rstrip() for x in f.readlines())))
|
185 |
+
|
186 |
+
# =================
|
187 |
+
w_i = -1
|
188 |
+
while w_i < len(data) - 1:
|
189 |
+
w_i += 1
|
190 |
+
line: str = data[w_i]
|
191 |
+
# =================
|
192 |
+
if not line.endswith('[np]'):
|
193 |
+
continue
|
194 |
+
# =================
|
195 |
+
n: str = data[w_i-1]
|
196 |
+
if n.startswith('*p'):
|
197 |
+
n = '旁白'
|
198 |
+
else:
|
199 |
+
if n.startswith('@nm'):
|
200 |
+
tmp = args2map(getCmdArgs(n))
|
201 |
+
if 'rt' in tmp:
|
202 |
+
n = tmp['rt']
|
203 |
+
else:
|
204 |
+
n = tmp['t']
|
205 |
+
|
206 |
+
if n in _n:
|
207 |
+
n = _n[n]
|
208 |
+
else:
|
209 |
+
_n[n] = clearT(n)
|
210 |
+
print(line)
|
211 |
+
|
212 |
+
if '「' in line:
|
213 |
+
line = line[line.index('「'):]
|
214 |
+
|
215 |
+
else:
|
216 |
+
print(line)
|
217 |
+
|
218 |
+
line = removeWait(line)
|
219 |
+
d = clearT(line)
|
220 |
+
if d:
|
221 |
+
sc[name].append(n + ':' + d)
|
222 |
+
|
223 |
+
# =================
|
224 |
+
|
225 |
+
for k, v in sc.items():
|
226 |
+
if v:
|
227 |
+
with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
|
228 |
+
f.write('\n'.join(v))
|
229 |
+
|
230 |
+
# =================
|
231 |
+
import json
|
232 |
+
tmp = json.dumps(_n, ensure_ascii=False, indent=4)
|