相思相爱洛丽塔@nenekochan
Browse files
v-corpus-zh/夜羊社/相思相爱洛丽塔/nenekochan_json.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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().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\yoruno\conversation\2016b-sssa2', ext='.json')
|
40 |
+
b = r'E:\tmp\yoruno\text'
|
41 |
+
|
42 |
+
# =================
|
43 |
+
|
44 |
+
sc = {}
|
45 |
+
|
46 |
+
_n = {
|
47 |
+
"narrator": "旁白",
|
48 |
+
"protagonist": "柄木", # 柄木丘
|
49 |
+
"heroine": "茉子" # 千岛茉子
|
50 |
+
}
|
51 |
+
|
52 |
+
# =================
|
53 |
+
import json
|
54 |
+
|
55 |
+
for path in a:
|
56 |
+
name = path[path.rindex('\\'):]
|
57 |
+
name = '相思相爱洛丽塔2'
|
58 |
+
if name not in sc:
|
59 |
+
sc[name] = []
|
60 |
+
print(name)
|
61 |
+
# =================
|
62 |
+
|
63 |
+
with open(path, 'r', encoding='utf-8') as json_file:
|
64 |
+
data = json.load(json_file)
|
65 |
+
|
66 |
+
for texts in data['conversation']:
|
67 |
+
request = texts['request']
|
68 |
+
response = texts['response']
|
69 |
+
texts = request + response
|
70 |
+
for line in texts:
|
71 |
+
n = line['speaker']
|
72 |
+
d = line['text']
|
73 |
+
if n in _n:
|
74 |
+
n = _n[n]
|
75 |
+
else:
|
76 |
+
_n[n] = clearT(n).replace('・', '&')
|
77 |
+
print(texts, n)
|
78 |
+
# =================
|
79 |
+
d = clearT(d)
|
80 |
+
if d:
|
81 |
+
sc[name].append(n + ':' + d)
|
82 |
+
|
83 |
+
|
84 |
+
# =================
|
85 |
+
|
86 |
+
for k, v in sc.items():
|
87 |
+
if v:
|
88 |
+
with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
|
89 |
+
f.write('\n'.join(v))
|
90 |
+
|
91 |
+
# =================
|
92 |
+
import json
|
93 |
+
tmp = json.dumps(_n, ensure_ascii=False, indent=4)
|
v-corpus-zh/夜羊社/相思相爱洛丽塔/相思相爱洛丽塔.txt.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c4541cd8f54e61672a886d6d36391c2567afc2610c8542dad761f988daeffca6
|
3 |
+
size 118193
|
v-corpus-zh/夜羊社/相思相爱洛丽塔/相思相爱洛丽塔2.txt.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9491b699e0145685e0b0126b39ac775dd5e4e69d8d30db480ea7eaa3bded4947
|
3 |
+
size 83142
|