Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
Limour commited on
Commit
2568290
·
verified ·
1 Parent(s): 72eb218

Upload 2 files

Browse files
v-corpus-zh/ASa/恋爱,我借走了/0.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4965a0c522598fa7747c3d637881273210d6325b270541476e2927197196d8f9
3
+ size 757610
v-corpus-zh/ASa/恋爱,我借走了/恋爱我借走了_ks.py ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 startsWithAlnum(s: str, _chrs):
47
+ retn = ''
48
+ for char in s:
49
+ if (char.isalnum()) or (char in _chrs):
50
+ retn += char
51
+ else:
52
+ break
53
+ return retn
54
+
55
+
56
+ def startsWithCmd(s: str, _chrs=None):
57
+ if _chrs is None:
58
+ _chrs = {'_', '@'}
59
+ cmd = startsWithAlnum(s, _chrs)
60
+ if cmd:
61
+ return s.startswith(cmd + ' ')
62
+ else:
63
+ return False
64
+
65
+
66
+ import re
67
+
68
+ reg_removeWait = re.compile(r'\[.+?]')
69
+
70
+
71
+ def removeWait(_line):
72
+ _tmp = reg_removeWait.sub('', _line)
73
+ if _tmp:
74
+ return _tmp
75
+ else:
76
+ return _line
77
+
78
+
79
+ def getCmdArgs(_cmd):
80
+ _args = ['']
81
+ _i = -1
82
+ _inQuota = ''
83
+ while _i < len(_cmd) - 1:
84
+ _i += 1
85
+ char = _cmd[_i]
86
+ if _inQuota:
87
+ _args[-1] += char
88
+ if char == _inQuota:
89
+ _inQuota = ''
90
+ elif char == '\\':
91
+ _i += 1
92
+ char = _cmd[_i]
93
+ _args[-1] += char
94
+ else:
95
+ pass
96
+ else:
97
+ if char == ' ':
98
+ _args.append('')
99
+ while _i < len(_cmd) - 1:
100
+ _i += 1
101
+ char = _cmd[_i]
102
+ if char != ' ':
103
+ _i -= 1
104
+ break
105
+ continue
106
+ elif char in {'"', "'"}:
107
+ _inQuota = char
108
+ else:
109
+ pass
110
+ _args[-1] += char
111
+ continue
112
+ return _args
113
+
114
+
115
+ def args2map(_args):
116
+ retn = {}
117
+ for _i in range(1, len(_args)):
118
+ _arg = _args[_i]
119
+ if '=' not in _arg:
120
+ if '=' in _arg:
121
+ _arg = _arg.replace('=', '=')
122
+ else:
123
+ continue
124
+ _idx = _arg.index('=')
125
+ _k = _arg[:_idx]
126
+ if '"' in _k or "'" in _k:
127
+ continue
128
+ _v = _arg[_idx + 1:]
129
+ if _v.startswith('"') or _v.startswith("'"):
130
+ _v = _v[1:len(_v) - 1]
131
+ retn[_k] = _v
132
+ return retn
133
+
134
+
135
+ # =================
136
+
137
+ a = get_all_files_in_directory(r'E:\tmp\恋爱我借走了\ks', ext='.ks')
138
+ b = r'D:\datasets\tmp'
139
+
140
+ # =================
141
+
142
+ sc = {}
143
+
144
+ _n = {
145
+ "咲希": "咲希",
146
+ "桃子": "桃子",
147
+ "绘未": "绘未",
148
+ "幸": "幸",
149
+ "八纯": "八纯",
150
+ "绘未妈妈": "绘未妈妈",
151
+ "椿": "椿",
152
+ "千夏": "千夏",
153
+ "梦乃": "梦乃",
154
+ "吾郎": "吾郎",
155
+ "小夏": "小夏",
156
+ "???": "?",
157
+ "椿母": "椿母",
158
+ "爱季": "爱季",
159
+ "複数": "复数",
160
+ "月": "月",
161
+ "Master": "Master",
162
+ "主人公": "主人公",
163
+ "千夏小夏母亲": "千夏小夏母亲",
164
+ "走散的长颈鹿": "走散的长颈鹿",
165
+ "海豹": "海豹",
166
+ "向导": "向导",
167
+ "新海家的亲戚": "新海家的亲戚",
168
+ "卡拉OK店员": "卡拉OK店员",
169
+ "天真的男孩": "天真的男孩",
170
+ "见多识广的女孩": "见多识广的女孩",
171
+ "拉面摊大叔": "拉面摊大叔",
172
+ "拉面摊的大叔": "拉面摊的大叔",
173
+ "超级不感兴趣的长颈鹿": "超级不感兴趣的长颈鹿",
174
+ "月的班主任": "月的班主任",
175
+ "急性子的斋藤": "急性子的斋藤",
176
+ "懦弱的川下": "懦弱的川下",
177
+ "粗野的豪田": "粗野的豪田",
178
+ "做主角的幸": "做主角的幸"
179
+ }
180
+
181
+ # =================
182
+ for path in a:
183
+ name = path[path.rindex('\\'):]
184
+ name = '0'
185
+ if name not in sc:
186
+ sc[name] = []
187
+ print(name)
188
+ # =================
189
+
190
+ with open(path, 'r', encoding='utf-16-le') as f:
191
+ data = list(filter(lambda x: x and (not x.startswith(';')),
192
+ (x.rstrip() for x in f.readlines())))
193
+
194
+ # =================
195
+ w_i = -1
196
+ while w_i < len(data) - 1:
197
+ w_i += 1
198
+ line: str = data[w_i]
199
+ # =================
200
+ if not line.endswith('[c]'):
201
+ continue
202
+ # =================
203
+ if line.startswith('[地'):
204
+ n = '旁白'
205
+ else:
206
+ if '[>> tx="『"]' in line:
207
+ line = line.replace('[>> tx="『"]', '[>>]')
208
+ line = line.replace('[<< tx="』"]', '[<<]')
209
+ assert line.endswith('[<<][c]') and '[>>]' in line
210
+ if line.startswith('[>>]'):
211
+ n: str = data[w_i-1]
212
+ else:
213
+ print(line)
214
+ n = line[:line.index('[>>]')]
215
+ line = line[len(n):]
216
+ print(n, line)
217
+
218
+ if n.startswith('[ネーム表示'):
219
+ n = n[n.index('【')+1:n.rindex('】')]
220
+ else:
221
+ if ' ' in n:
222
+ n = n[1:n.index(' ')]
223
+ else:
224
+ n = n.strip('[]')
225
+
226
+ if n in _n:
227
+ n = _n[n]
228
+ else:
229
+ _n[n] = clearT(n)
230
+ print(line)
231
+
232
+ line = removeWait(line)
233
+ d = clearT(line)
234
+ if d:
235
+ sc[name].append(n + ':' + d)
236
+
237
+ # =================
238
+
239
+ for k, v in sc.items():
240
+ if v:
241
+ with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
242
+ f.write('\n'.join(v))
243
+
244
+ # =================
245
+ import json
246
+ tmp = json.dumps(_n, ensure_ascii=False, indent=4)