|
|
import os |
|
|
|
|
|
import json |
|
|
from tqdm import tqdm |
|
|
import os |
|
|
import ast |
|
|
|
|
|
|
|
|
def read_json(file_path): |
|
|
with open(file_path, 'r', encoding='utf-8') as file: |
|
|
data = json.load(file) |
|
|
return data |
|
|
|
|
|
|
|
|
def write_json(file_path, data): |
|
|
with open(file_path, 'w', encoding='utf-8') as file: |
|
|
json.dump(data, file, ensure_ascii=False, indent=4) |
|
|
|
|
|
|
|
|
def read_jsonl(file_path): |
|
|
data = [] |
|
|
with open(file_path, 'r', encoding='utf-8') as f: |
|
|
for line in f: |
|
|
json_obj = json.loads(line.strip()) |
|
|
data.append(json_obj) |
|
|
return data |
|
|
|
|
|
|
|
|
def write_jsonl(file_path, data): |
|
|
with open(file_path, 'w', encoding='utf-8') as f: |
|
|
for item in data: |
|
|
json.dump(item, f, ensure_ascii=False) |
|
|
f.write('\n') |
|
|
|
|
|
|
|
|
data = read_json('/Users/baixuehai/Downloads/Benchmark/singleturn/singleturn.json') |
|
|
|
|
|
remove_data = [] |
|
|
for x in data: |
|
|
type = data[x]["edit_type"] |
|
|
if type == "remove": |
|
|
sub_path = data[x]["id"] |
|
|
img_path = os.path.join('/Users/baixuehai/Downloads/Benchmark/singleturn', sub_path) |
|
|
if os.path.exists(img_path): |
|
|
remove_data.append(data[x]) |
|
|
|
|
|
write_jsonl('/Users/baixuehai/Downloads/Benchmark/remove.jsonl', remove_data) |