forked from z814081807/DeepNER
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathconvert_test_data.py
More file actions
32 lines (20 loc) · 795 Bytes
/
convert_test_data.py
File metadata and controls
32 lines (20 loc) · 795 Bytes
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
import os
import json
from tqdm import trange
def save_info(data_dir, data, desc):
with open(os.path.join(data_dir, f'{desc}.json'), 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=2)
def convert_test_data_to_json(test_dir, save_dir):
test_examples = []
# process test examples
for i in trange(1500, 1997):
with open(os.path.join(test_dir, f'{i}.txt'), encoding='utf-8') as f:
text = f.read()
test_examples.append({'id': i,
'text': text})
save_info(save_dir, test_examples, 'test')
if __name__ == '__main__':
test_dir = './tcdata/juesai'
save_dir = './data/raw_data_random'
convert_test_data_to_json(test_dir, save_dir)
print('测试数据转换完成')