From ace8d52dfc5abcb874d416ac57ebedb7ead3ab71 Mon Sep 17 00:00:00 2001 From: zoujiwen Date: Fri, 27 Jun 2025 11:07:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20kg=5Flab=5F6.13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.27 更新‘其他费用’映射冗余修正;更新多项指标映射变量冗余修正 --- kg_lab_6.13/xml_to_json.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kg_lab_6.13/xml_to_json.py b/kg_lab_6.13/xml_to_json.py index 3da238e..55f77e6 100644 --- a/kg_lab_6.13/xml_to_json.py +++ b/kg_lab_6.13/xml_to_json.py @@ -365,6 +365,18 @@ def parse_indicator_string_to_json(indicator_str: str, output_path: str = "outpu # 解析为 JSON 对象 result = json.loads(indicator_str) + # 过滤 + for item in result: + mapping = item.get("指标描述", {}).get("指标映射") + if isinstance(mapping, str): + if "【工程费用】" in mapping: + cleaned = re.sub(r"@.*?\.", "", mapping) + item["指标描述"]["指标映射"] = cleaned + elif isinstance(mapping, list): + first_elem = mapping[0] + if first_elem.startswith("(") and first_elem.endswith(")"): + del mapping[0] + # 保存为 JSON 文件 with open(output_path, 'w', encoding='utf-8') as f: json.dump(result, f, ensure_ascii=False, indent=2)