Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
File size: 2,856 Bytes
93d319c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def get_all_files_in_directory(directory, ext=''):
    import os
    import re
    custom_sort_key_re = re.compile('([0-9]+)')

    def custom_sort_key(s):
        # 将字符串中的数字部分转换为整数,然后进行排序
        return [int(x) if x.isdigit() else x for x in custom_sort_key_re.split(s)]

    all_files = []
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.endswith(ext):
                file_path = os.path.join(root, file)
                all_files.append(file_path)
    return sorted(all_files, key=custom_sort_key)


def clearT():
    import unicodedata
    from opencc import OpenCC

    def full2half(input_str):
        return ''.join([unicodedata.normalize('NFKC', char) for char in input_str])

    cc = OpenCC('t2s')  # 't2s'表示繁体转简体

    def _clearT(s):
        s = cc.convert(full2half(s))
        return s.lstrip('n').strip().strip(r'\n').replace('\n', '\\n')

    return _clearT


clearT = clearT()

# =================

a = get_all_files_in_directory(r'E:\tmp\死馆\scn', ext='.txt.json')
b = r'D:\datasets\tmp'

# =================

sc = {}

_n = {
  "美亚": "美亚",
  "上位種族の男": "上位种族的男人",
  "濒死的女人": "濒死的女人",
  "上位种族的男人": "上位种族的男人",
  "腐烂的男人": "腐烂的男人",
  "夏花": "夏花",
  "女性": "女性",
  "女性客人": "女性客人",
  "米亚": "米亚",
  "心乃": "心乃",
  "爱梦": "爱梦",
  "形容枯槁的男人": "形容枯槁的男人",
  "上位种族的呢": "上位种族的男人",
  "???": "?",
  "女仆": "女仆",
  "永远生": "永远生"
}

# =================
import json

for path in a:
    name = path[path.rindex('\\'):]
    name = name[:3]
    if name not in sc:
        sc[name] = []
        print(name)
    # =================

    with open(path, 'r', encoding='utf-8') as json_file:
        data = json.load(json_file)

    # =================
    for texts in data['scenes']:
        try:
            for texts in texts['texts']:
                # print(texts)
                n = texts[0]
                if n is None:
                    n = '旁白'
                else:
                    if n in _n:
                        n = _n[n]
                    else:
                        _n[n] = clearT(n)
                        print(texts, n)

                # =================
                d = clearT(texts[2])
                if d:
                    sc[name].append(n + ':' + d)

        except KeyError:
            if type(texts) is not dict:
                print(texts)

# =================

for k, v in sc.items():
    with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
        f.write('\n'.join(v))

# =================
import json
tmp = json.dumps(_n, ensure_ascii=False, indent=2)