File size: 1,076 Bytes
5e81459
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import json
from tqdm import tqdm

# 要遍历的目录
base_dir = "/home/yz979/palmer_scratch/chengye/1000_arxiv/pdf2figure/data"

json_files = []
file_names = []

# 遍历目录
for root, dirs, files in os.walk(base_dir):
    for file in files:
        if file.endswith(".json"):
            full_path = os.path.join(root, file)
            json_files.append(full_path)
            file_names.append(file)

for i in tqdm(range(0,len(json_files))):
    table = {}
    with open(json_files[i],'r',encoding='utf-8')as f:
        data = json.load(f)
    for item in data:
        if item['figType'] == 'Table':
            item['renderURL'] = item['renderURL'].split('/')[-1]
            item.pop("imageText", None)
            table[item['name']] = item
    paper_path = '/home/yz979/palmer_scratch/chengye/1000_arxiv/papers/'+file_names[i]
    with open(paper_path,'r',encoding='utf-8')as f:
        data = json.load(f)    
    data['new_table'] = table
    with open(paper_path, "w", encoding="utf-8") as f:
        json.dump(data, f, ensure_ascii=False, indent=2)