Upload 2 files
Browse files
v-corpus-zh/Key/星之梦/1.txt.txt.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:24eaf6776490be92b78332ba8190fefc4f9d338e34f70e62e8ea190496c60a9f
|
3 |
+
size 73329
|
v-corpus-zh/Key/星之梦/星之梦_ns.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
39 |
+
a = get_all_files_in_directory(r'E:\tmp\星之梦', ext='.txt')
|
40 |
+
b = r'D:\datasets\tmp'
|
41 |
+
|
42 |
+
# =================
|
43 |
+
|
44 |
+
sc = {}
|
45 |
+
|
46 |
+
_n = {
|
47 |
+
"【???】": "?",
|
48 |
+
"【废墟猎人】": "废墟猎人",
|
49 |
+
"【梦美】": "梦美"
|
50 |
+
}
|
51 |
+
|
52 |
+
# =================
|
53 |
+
for path in a:
|
54 |
+
name = path[path.rindex('\\'):]
|
55 |
+
if name not in sc:
|
56 |
+
sc[name] = []
|
57 |
+
print(name)
|
58 |
+
# =================
|
59 |
+
|
60 |
+
with open(path, 'r', encoding='utf-8') as f:
|
61 |
+
data = list(filter(lambda x: x, (x.strip() for x in f.readlines())))
|
62 |
+
|
63 |
+
w_i = -1
|
64 |
+
while w_i < len(data) - 1:
|
65 |
+
w_i += 1
|
66 |
+
line = data[w_i]
|
67 |
+
if not (line.endswith('\\') or line.endswith('@')):
|
68 |
+
continue
|
69 |
+
line:str = line.rstrip(r'\@')
|
70 |
+
|
71 |
+
if line.startswith('【'):
|
72 |
+
assert '】' in line
|
73 |
+
idx = line.index('】') + 1
|
74 |
+
n = line[:idx]
|
75 |
+
if n in _n:
|
76 |
+
n = _n[n]
|
77 |
+
else:
|
78 |
+
_n[n] = clearT(n).strip('【】').replace('・', '&')
|
79 |
+
print(line)
|
80 |
+
line = line[idx:]
|
81 |
+
else:
|
82 |
+
n = '旁白'
|
83 |
+
d = clearT(line)
|
84 |
+
if d:
|
85 |
+
sc[name].append(n + ':' + d)
|
86 |
+
|
87 |
+
# =================
|
88 |
+
|
89 |
+
for k, v in sc.items():
|
90 |
+
with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
|
91 |
+
f.write('\n'.join(v))
|
92 |
+
|
93 |
+
# =================
|
94 |
+
import json
|
95 |
+
tmp = json.dumps(_n, ensure_ascii=False, indent=4)
|