全面更换orjson

This commit is contained in:
雅诺狐
2025-08-26 14:20:26 +08:00
committed by Windpicker-owo
parent 9f514d8799
commit ab3a36bfa7
44 changed files with 1163 additions and 1379 deletions

View File

@@ -1,4 +1,4 @@
import json
import orjson
import os
import time
from typing import Dict, List, Tuple
@@ -74,7 +74,7 @@ class KGManager:
# 保存段落hash到文件
with open(self.pg_hash_file_path, "w", encoding="utf-8") as f:
data = {"stored_paragraph_hashes": list(self.stored_paragraph_hashes)}
f.write(json.dumps(data, ensure_ascii=False, indent=4))
f.write(orjson.dumps(data, option=orjson.OPT_INDENT_2).decode('utf-8'))
def load_from_file(self):
"""从文件加载KG数据"""
@@ -88,7 +88,7 @@ class KGManager:
# 加载段落hash
with open(self.pg_hash_file_path, "r", encoding="utf-8") as f:
data = json.load(f)
data = orjson.loads(f.read())
self.stored_paragraph_hashes = set(data["stored_paragraph_hashes"])
# 加载实体计数