Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
File size: 2,463 Bytes
055dcb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from opencc import OpenCC
cc = OpenCC('t2s')  # 't2s'表示繁体转简体
from h_corpus import Fileset
import unicodedata
import json
def fullwidth_to_halfwidth(input_str):
    return ''.join([unicodedata.normalize('NFKC', char) for char in input_str])

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

a = Fileset(r'D:\datasets\tmp', ext='.jsonl')
b = r'D:\datasets\b-corpus\ChatHaruhi\RolePlaying'
for i in range(len(a)):
    path = a[i]
    name = path[path.rindex('\\')+1:path.rindex('.')]
    print(name)
    sc = []
    with open(path, encoding='utf-8') as f:
        for line in f:
            tmp = json.loads(line)
            if tmp['luotuo_openai'] == 'system_prompt':
                n = 'system'
                d = clearT(tmp['text'])
                sc.append(n + ':' + d)
                continue
            if tmp['luotuo_openai'] == 'config':
                continue
            tmp = tmp['text'].split('\n')
            for one in tmp:
                one = one.strip()
                if not one:
                    continue
                if ':「' in one:
                    one = one.replace(':「', ':「', 1)
                elif ': 「' in one:
                    one = one.replace(': 「', ':「', 1)
                elif one.startswith(':'):
                    one = '旁白:' + one[1:]
                elif ':「' in one or one.startswith('旁白:'):
                    pass
                elif one.startswith('旁白: '):
                    one = one.replace('旁白: ', '旁白:', 1)
                elif one.startswith('旁白:'):
                    one = one.replace('旁白:', '旁白:', 1)
                elif one.startswith('scene:'):
                    one = one.replace('scene:', '旁白:', 1)
                elif one.startswith('Narrator:'):
                    one = one.replace('Narrator:', 'Narrator:', 1)
                elif one.startswith('春日:'):
                    one = one.replace('春日:', '春日:', 1)
                elif ':' in one:
                    pass
                elif ':' in one:
                    one = one.replace(':', ':', 1)
                else:
                    one = '旁白:' + one
                    print(one)
                sc.append(one)
    if sc:
        with open(b + f'\\{name}.txt', 'w', encoding='utf-8') as f:
            f.write('\n'.join(sc))