Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
Limour commited on
Commit
7c34e0e
·
verified ·
1 Parent(s): ec226ab

Upload 2 files

Browse files
v-corpus-zh/Key/LOOPERS/LOOPERS.py ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import re
38
+ reg_rq = re.compile(r'(.+?)')
39
+ def removeQ(_s:str):
40
+ return reg_rq.sub('',_s).strip()
41
+
42
+
43
+ # =================
44
+
45
+ a = get_all_files_in_directory(r'E:\tmp\LOOPERS\Text', ext='.txt')
46
+ b = r'D:\datasets\tmp'
47
+
48
+ # =================
49
+
50
+ sc = {}
51
+
52
+ _n = {
53
+ "魔法师": "魔法师",
54
+ "少年": "少年",
55
+ "母亲": "母亲",
56
+ "护士": "护士",
57
+ "少女": "少女",
58
+ "父亲": "父亲",
59
+ "平良": "平良",
60
+ "昼田": "昼田",
61
+ "玲央奈": "玲央奈",
62
+ "女子": "女子",
63
+ "男子": "男子",
64
+ "大妈A": "大妈A",
65
+ "大妈B": "大妈B",
66
+ "大妈C": "大妈C",
67
+ "梦幻般的少女": "梦幻般的少女",
68
+ "米娅": "米娅",
69
+ "昼田的父亲": "昼田的父亲",
70
+ "急救员": "急救员",
71
+ "护士A": "护士A",
72
+ "医生": "医生",
73
+ "护士B": "护士B",
74
+ "护士C": "护士C",
75
+ "护士D": "护士D",
76
+ "西门": "西门",
77
+ "声音": "声音",
78
+ "莉塔朋德": "莉塔朋德",
79
+ "霍莉": "霍莉",
80
+ "让": "让",
81
+ "平良/昼田": "平良&昼田",
82
+ "售货员A": "售货员A",
83
+ "售货员B": "售货员B",
84
+ "售货员C": "售货员C",
85
+ "路人A": "路人A",
86
+ "路人B": "路人B",
87
+ "路人C": "路人C",
88
+ "路人D": "路人D",
89
+ "路人E": "路人E",
90
+ "路人F": "路人F",
91
+ "路人G": "路人G",
92
+ "路人H": "路人H",
93
+ "女": "女",
94
+ "玲奈央": "玲奈央",
95
+ "平良/让": "平良&让",
96
+ "米娅的母亲": "米娅的母亲",
97
+ "主刀医生": "主刀医生",
98
+ "主导医生": "主导医生",
99
+ "全员": "全员",
100
+ "「我更想追随平良所相信的希望……!」": "米娅",
101
+ "「我得向平良、道歉……我得道歉……」": "米娅",
102
+ "库洛": "库洛",
103
+ "凯": "凯",
104
+ "上班族": "上班族",
105
+ "主妇": "主妇",
106
+ "大学生": "大学生",
107
+ "教师": "教师",
108
+ "「―——对不起,对不起……」": "「―——对不起,对不起......」",
109
+ "所有人": "所有人",
110
+ "平良/米娅": "平良&米娅"
111
+ }
112
+
113
+ # =================
114
+ for path in a:
115
+ name = path[path.rindex('\\'):]
116
+ name = 'loopers'
117
+ if name not in sc:
118
+ sc[name] = []
119
+ print(name)
120
+ # =================
121
+
122
+ with open(path, 'r', encoding='utf-8') as f:
123
+ data = list(filter(lambda x: x,
124
+ (x.strip() for x in f.readlines())))
125
+ w_i = -1
126
+ while w_i < len(data) - 1:
127
+ w_i += 1
128
+ line: str = data[w_i]
129
+ if line in _n:
130
+ if line.startswith('「'):
131
+ pass
132
+ elif len(line) - len(_n[line]) > 4:
133
+ pass
134
+ elif data[w_i + 1].startswith('『'):
135
+ assert removeQ(data[w_i + 1]).endswith('』')
136
+ data[w_i + 1] = f'「{data[w_i + 1]}」'
137
+ print(data[w_i + 1])
138
+ continue
139
+ elif not (data[w_i + 1].startswith('「') or data[w_i + 1].startswith('(')):
140
+ pass
141
+ else:
142
+ continue
143
+ # print(line)
144
+ if line.startswith('「'):
145
+ n = data[w_i-1]
146
+ if n in _n:
147
+ n = _n[n]
148
+ else:
149
+ pass
150
+ _n[n] = clearT(n).replace('・', '&')
151
+ print(n, line)
152
+ tmp = []
153
+ while not (removeQ(line).endswith('」')):
154
+ tmp.append(line)
155
+ w_i += 1
156
+ line: str = data[w_i]
157
+ if line in _n:
158
+ if data[w_i + 1].startswith('「') or data[w_i + 1].startswith('('):
159
+ w_i -= 1
160
+ break
161
+ else:
162
+ tmp.append(line)
163
+ line = '\\n'.join(tmp)
164
+ elif line.startswith('(') and data[w_i-1] in _n:
165
+ n = data[w_i-1]
166
+ n = _n[n]
167
+ tmp = []
168
+ while not line.endswith(')'):
169
+ tmp.append(line)
170
+ w_i += 1
171
+ line: str = data[w_i]
172
+ if line in _n:
173
+ if data[w_i + 1].startswith('「') or data[w_i + 1].startswith('('):
174
+ w_i -= 1
175
+ break
176
+ else:
177
+ tmp.append(line)
178
+ line = '\\n'.join(tmp)
179
+ else:
180
+ n = '旁白'
181
+ d = clearT(line)
182
+ if d:
183
+ sc[name].append(n + ':' + d)
184
+
185
+ # =================
186
+
187
+ for k, v in sc.items():
188
+ if v:
189
+ with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
190
+ f.write('\n'.join(v))
191
+ # =================
192
+ import json
193
+ tmp = json.dumps(_n, ensure_ascii=False, indent=4)
v-corpus-zh/Key/LOOPERS/loopers.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1133bfc9a509a31554f53fb7ff565525e571a3840d436a5638817c572690a3bf
3
+ size 156615