Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
Limour commited on
Commit
38b649d
·
verified ·
1 Parent(s): 445c6a9

雪色暗号

Browse files
v-corpus-zh/WonderFool/雪色暗号/01.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2da9343cfbdcd3113fb4062cfa95d09c297055f59cae2cf776f7aa47d2a9fb24
3
+ size 156492
v-corpus-zh/WonderFool/雪色暗号/02.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d9d189d9d4258647771cc72aa80973ec7532e8ee58bf1b7151fca72d019d25e
3
+ size 134293
v-corpus-zh/WonderFool/雪色暗号/03.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fd93ed608841bae55d9664b88cf76ee08720be26f048d4c863f18877e4d05e62
3
+ size 137009
v-corpus-zh/WonderFool/雪色暗号/04.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:145af81b281b4b0206f0cb083ce191d616027a86c29d9e59a4ea6841ed1739c8
3
+ size 135688
v-corpus-zh/WonderFool/雪色暗号/雪色暗号_ast.py ADDED
@@ -0,0 +1,355 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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().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
+ def getBracketContent(_left='{', _right='}', _start=0):
144
+ global data, w_i
145
+ retn = _left
146
+ _start += 1
147
+ w_i -= 1
148
+ while w_i < len(data) - 1:
149
+ w_i += 1
150
+ _line: str = data[w_i] + '\n'
151
+ # =================
152
+ w_j = _start - 1
153
+ _inQuota = ''
154
+ while w_j < len(_line) - 1:
155
+ w_j += 1
156
+ char = _line[w_j]
157
+ # =================
158
+ if _inQuota:
159
+ retn += char
160
+ if char == _inQuota:
161
+ _inQuota = ''
162
+ elif char == '\\':
163
+ w_j += 1
164
+ char = _line[w_j]
165
+ retn += char
166
+ else:
167
+ pass
168
+ else:
169
+ if char in {'"', "'"}:
170
+ _inQuota = char
171
+ retn += char
172
+ elif char == _left:
173
+ _retn, _line, w_j = getBracketContent(_left, _right, w_j)
174
+ retn += _retn
175
+ elif char == _right:
176
+ retn += char
177
+ return retn, _line, w_j
178
+ else:
179
+ retn += char
180
+ _start = 0
181
+ return retn, '', 0
182
+
183
+
184
+ def ast2list(_ast: str, _start=0):
185
+ retn = [['', '']]
186
+ # =================
187
+ w_j = _start
188
+ _inQuota = ''
189
+ while w_j < len(_ast) - 1:
190
+ w_j += 1
191
+ char = _ast[w_j]
192
+ # =================
193
+ if _inQuota:
194
+ if char == _inQuota:
195
+ _inQuota = ''
196
+ elif char == '\\':
197
+ retn[-1][1] += char
198
+ w_j += 1
199
+ char = _ast[w_j]
200
+ retn[-1][1] += char
201
+ else:
202
+ retn[-1][1] += char
203
+ else:
204
+ if char in {'"', "'"}:
205
+ _inQuota = char
206
+ # retn[-1][1] += char
207
+ elif char == '{':
208
+ _retn, w_j = ast2list(_ast, w_j)
209
+ retn[-1][1] = _retn
210
+ elif char == '}':
211
+ return retn, w_j
212
+ elif char == ',':
213
+ retn.append(['', ''])
214
+ elif char == '=':
215
+ pass
216
+ else:
217
+ if char.strip():
218
+ retn[-1][0] += char
219
+
220
+ return [['', '']], 0
221
+
222
+
223
+ def astGet(_astOj, _key=''):
224
+ if _key:
225
+ for k, v in _astOj:
226
+ if k == _key:
227
+ return v
228
+ else:
229
+ _d = ''
230
+ for k, v in _astOj:
231
+ if not k:
232
+ if type(v) is str:
233
+ _d += v
234
+ return _d
235
+
236
+
237
+ # =================
238
+
239
+ a = get_all_files_in_directory(r'E:\tmp\雪色暗号_\ast\script', ext='.ast')
240
+ b = r'E:\tmp\雪色暗号_\ast\text'
241
+
242
+ # =================
243
+
244
+ sc = {}
245
+
246
+ _n = {
247
+ "斯维": "斯维",
248
+ "香子": "香子",
249
+ "香子的父亲": "香子的父亲",
250
+ "美玖": "美玖",
251
+ "牛顿": "牛顿",
252
+ "宗冬": "宗冬",
253
+ "广中": "广中",
254
+ "亲宗冬的母亲": "亲宗冬的母亲",
255
+ "宗冬&美玖&广中": "宗冬&美玖&广中",
256
+ "少女": "少女",
257
+ "宗冬&广中": "宗冬&广中",
258
+ "美玖的母亲": "美玖的母亲",
259
+ "美玖&广中&宗冬&香子": "美玖&广中&宗冬&香子",
260
+ "芽衣": "芽衣",
261
+ "莉子": "莉子",
262
+ "同学1": "同学1",
263
+ "老婆婆": "老婆婆",
264
+ "唔阿嬷": "唔阿嬷",
265
+ "雅惠": "雅惠",
266
+ "美玖&斯维": "美玖&斯维",
267
+ "???": "?",
268
+ "结": "结",
269
+ "皋": "皋",
270
+ "居民1": "居民1",
271
+ "真一": "真一",
272
+ "居民2": "居民2",
273
+ "美佐江": "美佐江",
274
+ "幸代": "幸代",
275
+ "宗冬的父亲": "宗冬的父亲",
276
+ "全员": "全员",
277
+ "柊佳": "柊佳",
278
+ "中田老师": "中田老师",
279
+ "宗冬&美玖": "宗冬&美玖",
280
+ "美玖的父亲": "美玖的父亲",
281
+ "广中的父亲": "广中的父亲",
282
+ "新闻记者": "新闻记者",
283
+ "美玖&香子": "美玖&香子",
284
+ "宗冬的父亲&母": "宗冬的父亲&母",
285
+ "广播": "广播",
286
+ "宗冬&香子": "宗冬&香子",
287
+ "斯维&广中": "斯维&广中",
288
+ "访谈记者": "访谈记者",
289
+ "美玖&斯维&广中": "美玖&斯维&广中",
290
+ "滑雪社社员1": "滑雪社社员1",
291
+ "宗冬&结": "宗冬&结"
292
+ }
293
+
294
+ reg_ast = re.compile(r'^\s*cn\s*=\s*\{')
295
+ reg_select = re.compile(r'\s*select\s*=\s*\{')
296
+ # =================
297
+ for path in a:
298
+ name: str = path[path.rindex('\\') + 1:]
299
+ name = name[:2]
300
+ if name not in sc:
301
+ sc[name] = []
302
+ print(name)
303
+ # =================
304
+
305
+ with open(path, 'r', encoding='utf-8') as f:
306
+ data = list(filter(lambda x: x,
307
+ (x.rstrip() for x in f.readlines())))
308
+
309
+ # =================
310
+ w_i = -1
311
+ while w_i < len(data) - 1:
312
+ w_i += 1
313
+ line: str = data[w_i]
314
+ # =================
315
+ tmp = reg_select.match(line)
316
+ if tmp is not None:
317
+ tmp = getBracketContent(_start=tmp.end() - 1)[0]
318
+ continue
319
+ tmp = reg_ast.match(line)
320
+ if tmp is None:
321
+ continue
322
+ tmp = getBracketContent(_start=tmp.end() - 1)[0]
323
+ tmp = ast2list(tmp)[0]
324
+ # tmp = astGet(tmp, 'cn')
325
+ assert len(tmp) == 2
326
+ tmp = tmp[0][1]
327
+ n = astGet(tmp, 'name')
328
+ if n:
329
+ if len(n) == 1:
330
+ n = n[0][1]
331
+ else:
332
+ n = n[1][1]
333
+ if n in _n:
334
+ n = _n[n]
335
+ else:
336
+ _n[n] = clearT(n.strip('【】')).replace('???', '?')
337
+ print(n, tmp)
338
+ else:
339
+ n = '旁白'
340
+ d = astGet(tmp)
341
+ d = clearT(d)
342
+ if d:
343
+ sc[name].append(n + ':' + d)
344
+
345
+ # =================
346
+
347
+ for k, v in sc.items():
348
+ if v:
349
+ with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
350
+ f.write('\n'.join(v))
351
+
352
+ # =================
353
+ import json
354
+
355
+ tmp = json.dumps(_n, ensure_ascii=False, indent=4)