Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
Limour commited on
Commit
de487bb
·
verified ·
1 Parent(s): 5acb7e7

保健室的老师与哥特萝莉校医@米饭

Browse files
v-corpus-zh/Citrus/保健室的老师系列/保健室的老师与哥特萝莉校医/01.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6383a4d1dc43120081ae71cc1cda1453b86578c5ba513e40aeaa25d4df938776
3
+ size 193618
v-corpus-zh/Citrus/保健室的老师系列/保健室的老师与哥特萝莉校医/02.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c80f6fbc80a64dc4525784e4de94285fbff99b20d0c6c5523182eb312e994411
3
+ size 150771
v-corpus-zh/Citrus/保健室的老师系列/保健室的老师与哥特萝莉校医/保健室的老师与哥特萝莉校医_ast.py ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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\保健室的老师与哥特萝莉校医_\text'
241
+
242
+ # =================
243
+
244
+ sc = {}
245
+
246
+ _n = {
247
+ "蒼空": "苍空",
248
+ "女子生徒": "女学生",
249
+ "シロバナ": "白花",
250
+ "鈴": "铃",
251
+ "オトヒメ": "乙姬",
252
+ "玲子": "玲子",
253
+ "夢歌": "梦歌",
254
+ "咲羽": "咲羽",
255
+ "瑞海": "瑞海",
256
+ "七菜": "七菜",
257
+ "生徒会役員A": "学生会干部A",
258
+ "生徒会役員B": "学生会干部B",
259
+ "???": "?",
260
+ "島梟": "岛枭",
261
+ "朱鷺野": "朱鹭野",
262
+ "永遠": "永远",
263
+ "夕七": "夕七",
264
+ "ヒグマ": "棕熊",
265
+ "麻衣子": "麻衣子",
266
+ "マロウド": "麻吕",
267
+ "オソママチ": "慢町",
268
+ "乙姬": "乙姬",
269
+ "苍空": "苍空",
270
+ "小白": "小白",
271
+ "麻吕": "麻吕",
272
+ "ハルアンテ": "春枭" # 岛枭的CP
273
+ }
274
+
275
+ reg_ast = re.compile(r'^\[\d+]=\{')
276
+
277
+ # =================
278
+ for path in a:
279
+ name: str = path[path.rindex('\\') + 1:]
280
+ name = name[:2]
281
+ if name not in sc:
282
+ sc[name] = []
283
+ print(name)
284
+ # =================
285
+
286
+ with open(path, 'r', encoding='utf-8') as f:
287
+ data = list(filter(lambda x: x,
288
+ (x.rstrip() for x in f.readlines())))
289
+
290
+ # =================
291
+ w_i = -1
292
+ while w_i < len(data) - 1:
293
+ w_i += 1
294
+ line: str = data[w_i]
295
+ # =================
296
+ tmp = reg_ast.match(line)
297
+ if tmp is None:
298
+ continue
299
+ tmp = getBracketContent(_start=tmp.end() - 1)[0]
300
+ tmp = ast2list(tmp)[0]
301
+ n = astGet(tmp, 'name')
302
+ if n:
303
+ if len(n) == 1:
304
+ n = n[0][1]
305
+ else:
306
+ n = astGet(n, 'ja')
307
+ if n in _n:
308
+ n = _n[n]
309
+ else:
310
+ _n[n] = clearT(n.strip('【】')).replace('???', '?')
311
+ print(n, tmp)
312
+ else:
313
+ n = '旁白'
314
+ d = astGet(tmp, 'ja')
315
+ assert len(d) == 2
316
+ d = d[0][1]
317
+ d = astGet(d)
318
+ d = clearT(d)
319
+ if d:
320
+ sc[name].append(n + ':' + d)
321
+
322
+ # =================
323
+
324
+ for k, v in sc.items():
325
+ if v:
326
+ with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
327
+ f.write('\n'.join(v))
328
+
329
+ # =================
330
+ import json
331
+
332
+ tmp = json.dumps(_n, ensure_ascii=False, indent=4)