Upload 3 files
Browse files
v-corpus-zh/Minori/永不落幕的前奏诗/nsdec.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8e566e37dd3813a4f25954f2c497c6e31b0476ad14b1dc06f97aa3ba64788a98
|
3 |
+
size 15747
|
v-corpus-zh/Minori/永不落幕的前奏诗/qzs_ns.py
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
39 |
+
a = get_all_files_in_directory(r'E:\tmp\yblm', ext='.txt')
|
40 |
+
b = r'D:\datasets\tmp'
|
41 |
+
|
42 |
+
# =================
|
43 |
+
|
44 |
+
sc = {}
|
45 |
+
|
46 |
+
_n = {
|
47 |
+
"[ 终 ": "终",
|
48 |
+
"[永 远": "永远",
|
49 |
+
"[真 响": "真响",
|
50 |
+
"[真 希": "真希",
|
51 |
+
"[苍 太": "苍太",
|
52 |
+
"[ 静 ": "静",
|
53 |
+
"[ 遥 ": "遥",
|
54 |
+
"[ ? ": "?",
|
55 |
+
"[": "旁白",
|
56 |
+
"[男 性": "男性",
|
57 |
+
"[孩子A": "孩子A",
|
58 |
+
"[孩子B": "孩子B",
|
59 |
+
"[学生A": "学生A",
|
60 |
+
"[学生B": "学生B",
|
61 |
+
"[二 人": "二人",
|
62 |
+
"[电 话": "电话",
|
63 |
+
"[木 下": "木下",
|
64 |
+
}
|
65 |
+
# =================
|
66 |
+
import re
|
67 |
+
cselr = re.compile(r'(",\*)|(,")')
|
68 |
+
for path in a:
|
69 |
+
name = path[path.rindex('\\'):]
|
70 |
+
if name not in sc:
|
71 |
+
sc[name] = []
|
72 |
+
print(name)
|
73 |
+
# =================
|
74 |
+
|
75 |
+
with open(path, 'r', encoding='utf-8') as f:
|
76 |
+
data = f.readlines()
|
77 |
+
|
78 |
+
# =================
|
79 |
+
for i,line in enumerate(data):
|
80 |
+
line = line.strip()
|
81 |
+
if line.startswith(';'):
|
82 |
+
if not line.isascii():
|
83 |
+
# print(line)
|
84 |
+
pass
|
85 |
+
continue
|
86 |
+
if line.endswith('\\'):
|
87 |
+
assert data[i+1].startswith('nend') # 懒得处理了
|
88 |
+
if not line.startswith('['):
|
89 |
+
if not line.isascii():
|
90 |
+
# print(line)
|
91 |
+
pass
|
92 |
+
continue
|
93 |
+
line = line.rstrip('\\')
|
94 |
+
if line.endswith('』'):
|
95 |
+
line = line.replace(']『', ']「')
|
96 |
+
line = line[:-1] + '」'
|
97 |
+
tmp = line.split(']「')
|
98 |
+
if len(tmp) == 1:
|
99 |
+
if not tmp[0].startswith('[|]'):
|
100 |
+
print(tmp)
|
101 |
+
else:
|
102 |
+
pass
|
103 |
+
n = '旁白'
|
104 |
+
idx = tmp[0].index(']')
|
105 |
+
tmp[0] = tmp[0][idx+1:]
|
106 |
+
elif len(tmp) == 2:
|
107 |
+
n = tmp[0].split('|')
|
108 |
+
assert len(n) == 2
|
109 |
+
n = n[0]
|
110 |
+
if n in _n:
|
111 |
+
n = _n[n]
|
112 |
+
else:
|
113 |
+
_n[n] = clearT(n)
|
114 |
+
print(line)
|
115 |
+
tmp[-1] = '「' + tmp[-1]
|
116 |
+
else:
|
117 |
+
print(tmp)
|
118 |
+
assert False
|
119 |
+
d = tmp[-1]
|
120 |
+
d = clearT(d)
|
121 |
+
if d:
|
122 |
+
sc[name].append(n + ':' + d)
|
123 |
+
# =================
|
124 |
+
|
125 |
+
for k, v in sc.items():
|
126 |
+
with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
|
127 |
+
f.write('\n'.join(v))
|
128 |
+
|
129 |
+
# =================
|
130 |
+
import json
|
131 |
+
tmp = json.dumps(_n, ensure_ascii=False, indent=2)
|
v-corpus-zh/Minori/永不落幕的前奏诗/result.txt.txt.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:073c114ef5332df95e422844dd566e987e6579bd203c9a267a812fc0371bb4a2
|
3 |
+
size 570464
|