64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
import os
|
|
from dotenv import load_dotenv
|
|
from elasticsearch import Elasticsearch, helpers
|
|
import json
|
|
import re
|
|
|
|
load_dotenv()
|
|
|
|
def run_folder(dir):
|
|
pattern = re.compile(r"output_(\d+)\.json$")
|
|
process_ids = []
|
|
filename = ''
|
|
processed_id = []
|
|
# processed_id_set = set(processed_id)
|
|
|
|
try:
|
|
for filename in os.listdir(dir):
|
|
|
|
# match = pattern.match(filename)
|
|
# if match:
|
|
# # Read JSON file
|
|
# data = {}
|
|
print(filename)
|
|
with open(dir + filename, 'r', encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
for item in data :
|
|
processed_id.append(item["id"])
|
|
|
|
except json.JSONDecodeError as e:
|
|
print(f"File not found: {filename}")
|
|
raise ValueError(f"Failed to parse JSON file: {str(e)}")
|
|
except FileNotFoundError:
|
|
raise FileNotFoundError(f"File not found: {filename}")
|
|
|
|
|
|
return processed_id
|
|
|
|
|
|
|
|
processed_id_1 = run_folder("data/codes_reaseon_oss/data_g3090/")
|
|
print("processed_id 1 ", len(processed_id_1))
|
|
processed_id_2 = run_folder("data/codes_reaseon_oss/data_h100/")
|
|
print("processed_id 2 ", len(processed_id_2))
|
|
|
|
|
|
processed_id_1.extend(processed_id_2)
|
|
print("total ", len(processed_id_1))
|
|
|
|
processed_id_set1 = set(processed_id_1)
|
|
print("total set ", len(processed_id_set1))
|
|
|
|
with open("data/codes_reaseon_oss/process_tt_id.json", "w") as f:
|
|
json.dump(list(processed_id_set1), f)
|
|
|
|
|
|
|
|
# with open("data/codes_reaseon_oss/section_codes.json", 'r', encoding="utf-8") as f:
|
|
# data = json.load(f)
|
|
# print("section_codes ", len(data.items()))
|
|
|
|
# with open("data/codes_reaseon_oss/mj_qa_section.json", 'r', encoding="utf-8") as f:
|
|
# data = json.load(f)
|
|
# print("mj_qa_section ", len(data))
|