|
@@ -19,6 +19,7 @@
|
|
|
"""
|
|
"""
|
|
|
import json
|
|
import json
|
|
|
import sys
|
|
import sys
|
|
|
|
|
+import numpy as np
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
from typing import Dict, Any, List, Optional
|
|
from typing import Dict, Any, List, Optional
|
|
|
from loguru import logger
|
|
from loguru import logger
|
|
@@ -33,6 +34,18 @@ from .visualization_utils import VisualizationUtils
|
|
|
from .normalize_financial_numbers import normalize_markdown_table, normalize_json_table
|
|
from .normalize_financial_numbers import normalize_markdown_table, normalize_json_table
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+class NumpyEncoder(json.JSONEncoder):
|
|
|
|
|
+ """自定义JSON编码器,处理numpy类型"""
|
|
|
|
|
+ def default(self, obj):
|
|
|
|
|
+ if isinstance(obj, np.integer):
|
|
|
|
|
+ return int(obj)
|
|
|
|
|
+ elif isinstance(obj, np.floating):
|
|
|
|
|
+ return float(obj)
|
|
|
|
|
+ elif isinstance(obj, np.ndarray):
|
|
|
|
|
+ return obj.tolist()
|
|
|
|
|
+ return super().default(obj)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
class OutputFormatterV2:
|
|
class OutputFormatterV2:
|
|
|
"""
|
|
"""
|
|
|
统一输出格式化器
|
|
统一输出格式化器
|
|
@@ -161,7 +174,7 @@ class OutputFormatterV2:
|
|
|
# 3. 保存 middle.json
|
|
# 3. 保存 middle.json
|
|
|
if output_config.get('save_json', True):
|
|
if output_config.get('save_json', True):
|
|
|
json_path = doc_output_dir / f"{doc_name}_middle.json"
|
|
json_path = doc_output_dir / f"{doc_name}_middle.json"
|
|
|
- json_content = json.dumps(middle_json, ensure_ascii=False, indent=2)
|
|
|
|
|
|
|
+ json_content = json.dumps(middle_json, ensure_ascii=False, indent=2, cls=NumpyEncoder)
|
|
|
|
|
|
|
|
# 金额数字标准化
|
|
# 金额数字标准化
|
|
|
normalize_numbers = output_config.get('normalize_numbers', True)
|
|
normalize_numbers = output_config.get('normalize_numbers', True)
|