From 4d51b15dcf7d91116adf84ac46b381d5c34f760f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=8C=AE=E7=BB=B4?= Date: Wed, 9 Jul 2025 22:19:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BB=E5=8F=96csv?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database.py | 12 ++++++------ src/matcher.py | 6 +++--- test_config.yaml | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/database.py b/src/database.py index 8b083ee..3887fed 100644 --- a/src/database.py +++ b/src/database.py @@ -59,9 +59,9 @@ class CSVManager: if missing_columns: raise ValueError(f"A_TREE CSV文件缺少必要列: {missing_columns}") - # 确保数据类型正确 - df['Id'] = df['Id'].astype(int) - df['Pid'] = df['Pid'].astype(int) + # 确保所有列都作为字符串处理 + df['Id'] = df['Id'].astype(str) + df['Pid'] = df['Pid'].astype(str) df['name'] = df['name'].astype(str) logger.info(f"A_TREE CSV文件读取成功: {self.a_csv_path} ({len(df)} 条记录)") @@ -92,9 +92,9 @@ class CSVManager: if missing_columns: raise ValueError(f"B_TREE CSV文件缺少必要列: {missing_columns}") - # 确保数据类型正确 - df['Id'] = df['Id'].astype(int) - df['Pid'] = df['Pid'].astype(int) + # 确保所有列都作为字符串处理 + df['Id'] = df['Id'].astype(str) + df['Pid'] = df['Pid'].astype(str) df['name'] = df['name'].astype(str) logger.info(f"B_TREE CSV文件读取成功: {self.b_csv_path} ({len(df)} 条记录)") diff --git a/src/matcher.py b/src/matcher.py index fcaa556..25fa15a 100644 --- a/src/matcher.py +++ b/src/matcher.py @@ -154,13 +154,13 @@ class InstitutionMatcher: return keywords - def get_parent_hierarchy(self, tree_data: pd.DataFrame, node_id: int) -> List[Dict[str, Any]]: + def get_parent_hierarchy(self, tree_data: pd.DataFrame, node_id: str) -> List[Dict[str, Any]]: """ 获取节点的父级层次结构 Args: tree_data: 树形数据 - node_id: 节点ID + node_id: 节点ID(字符串类型) Returns: 父级层次结构列表 @@ -168,7 +168,7 @@ class InstitutionMatcher: hierarchy = [] current_id = node_id - while current_id != 0: + while current_id != '0': node = tree_data[tree_data['Id'] == current_id] if node.empty: break diff --git a/test_config.yaml b/test_config.yaml index 4afda6a..4dac62d 100644 --- a/test_config.yaml +++ b/test_config.yaml @@ -1,9 +1,9 @@ # CSV文件配置 csv: # A_TREE CSV文件路径 - a_csv_path: "data/a_20250709_020703.csv" + a_csv_path: "data/a_20250709_221723.csv" # B_TREE CSV文件路径 - b_csv_path: "data/b_20250709_020703.csv" + b_csv_path: "data/b_20250709_221723.csv" # 输出CSV文件路径 output_csv_path: "test_output/ab.csv"