Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
Limour commited on
Commit
707b905
·
verified ·
1 Parent(s): 5243d31

Upload 2 files

Browse files
v-corpus-zh/StageNana/水仙/水仙1&2/0.txt.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:075ae92b12e3a87d947cac82ccca8648c56d5c01e151069c575c038f15bdd0e3
3
+ size 180974
v-corpus-zh/StageNana/水仙/水仙1&2/水仙.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.lstrip('n').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):
47
+ retn = ''
48
+ for char in s:
49
+ if char.isalnum():
50
+ retn += char
51
+ else:
52
+ break
53
+ return retn
54
+
55
+ # =================
56
+
57
+ a = get_all_files_in_directory(r'E:\tmp\水仙', ext='.txt')
58
+ b = r'D:\datasets\tmp'
59
+
60
+ # =================
61
+
62
+ sc = {}
63
+
64
+ _n = {
65
+ "setsumi": "濑津美",
66
+ "himeko": "姬子",
67
+ "chihiro": "千寻",
68
+ "yuka": "优花",
69
+ "hime2": "姬子",
70
+ "setu": "濑津美",
71
+ "sabu": "同楼的姐姐",
72
+ "03": "声音",
73
+ "hime1": "姬子",
74
+ "mama": "妈妈",
75
+ "z42r": "声音",
76
+ "onnanoko": "尼洛",
77
+ "new": "濑津美",
78
+ "n068": "濑津美"
79
+ }
80
+
81
+ _n = {k:_n[k] for k in sorted(_n.keys(), key=len, reverse=True)}
82
+ # =================
83
+ import re
84
+ reg_n = re.compile(r'\[Talk( [^] ]+?)? name=([^] ]+?)]')
85
+ for path in a:
86
+ name = path[path.rindex('\\'):]
87
+ # name = name[:6]
88
+ if name not in sc:
89
+ sc[name] = []
90
+ print(name)
91
+ # =================
92
+
93
+ with open(path, 'r', encoding='utf-8') as f:
94
+ data = f.readlines()
95
+
96
+ for i, line in enumerate(data):
97
+ line = line.strip()
98
+ if not line.endswith('\\'):
99
+ continue
100
+ for j in range(i, 0, -1):
101
+ if not data[j].strip():
102
+ break
103
+ tmp = data[j+1:i+1]
104
+ if tmp[0].startswith(';'):
105
+ continue
106
+ if tmp[0].isascii():
107
+ if tmp[0].startswith('dwave'):
108
+ if tmp[1].startswith(';'):
109
+ continue
110
+ idx = tmp[0].rindex('\\')
111
+ n = startsWithAlnum(tmp[0][idx+1:])
112
+ if n in _n:
113
+ n = _n[n]
114
+ else:
115
+ _n[n] = clearT(n)
116
+ print(tmp, n)
117
+ d = ''.join(tmp[1:])
118
+ else:
119
+ print(tmp)
120
+ else:
121
+ assert not tmp[0].startswith('dwave')
122
+ n = '旁白'
123
+ d = ''.join(tmp)
124
+ # print(tmp)
125
+ d = clearT(d)
126
+ if d:
127
+ sc[name].append(n + ':' + d)
128
+ # =================
129
+
130
+ for k, v in sc.items():
131
+ with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
132
+ f.write('\n'.join(v))
133
+
134
+ # =================
135
+ import json
136
+ tmp = json.dumps(_n, ensure_ascii=False, indent=2)