fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -5,7 +5,6 @@ InsightFlow Multimodal Entity Linker - Phase 7
|
||||
"""
|
||||
|
||||
import uuid
|
||||
from typing import List, Dict, Optional, Tuple, Set
|
||||
from dataclasses import dataclass
|
||||
from difflib import SequenceMatcher
|
||||
|
||||
@@ -28,7 +27,7 @@ class MultimodalEntity:
|
||||
source_id: str
|
||||
mention_context: str
|
||||
confidence: float
|
||||
modality_features: Dict = None # 模态特定特征
|
||||
modality_features: dict = None # 模态特定特征
|
||||
|
||||
def __post_init__(self):
|
||||
if self.modality_features is None:
|
||||
@@ -55,7 +54,7 @@ class AlignmentResult:
|
||||
"""对齐结果"""
|
||||
|
||||
entity_id: str
|
||||
matched_entity_id: Optional[str]
|
||||
matched_entity_id: str | None
|
||||
similarity: float
|
||||
match_type: str # exact, fuzzy, embedding
|
||||
confidence: float
|
||||
@@ -66,9 +65,9 @@ class FusionResult:
|
||||
"""知识融合结果"""
|
||||
|
||||
canonical_entity_id: str
|
||||
merged_entity_ids: List[str]
|
||||
fused_properties: Dict
|
||||
source_modalities: List[str]
|
||||
merged_entity_ids: list[str]
|
||||
fused_properties: dict
|
||||
source_modalities: list[str]
|
||||
confidence: float
|
||||
|
||||
|
||||
@@ -117,7 +116,7 @@ class MultimodalEntityLinker:
|
||||
# 编辑距离相似度
|
||||
return SequenceMatcher(None, s1, s2).ratio()
|
||||
|
||||
def calculate_entity_similarity(self, entity1: Dict, entity2: Dict) -> Tuple[float, str]:
|
||||
def calculate_entity_similarity(self, entity1: dict, entity2: dict) -> tuple[float, str]:
|
||||
"""
|
||||
计算两个实体的综合相似度
|
||||
|
||||
@@ -159,8 +158,8 @@ class MultimodalEntityLinker:
|
||||
return combined_sim, "none"
|
||||
|
||||
def find_matching_entity(
|
||||
self, query_entity: Dict, candidate_entities: List[Dict], exclude_ids: Set[str] = None
|
||||
) -> Optional[AlignmentResult]:
|
||||
self, query_entity: dict, candidate_entities: list[dict], exclude_ids: set[str] = None
|
||||
) -> AlignmentResult | None:
|
||||
"""
|
||||
在候选实体中查找匹配的实体
|
||||
|
||||
@@ -201,11 +200,11 @@ class MultimodalEntityLinker:
|
||||
def align_cross_modal_entities(
|
||||
self,
|
||||
project_id: str,
|
||||
audio_entities: List[Dict],
|
||||
video_entities: List[Dict],
|
||||
image_entities: List[Dict],
|
||||
document_entities: List[Dict],
|
||||
) -> List[EntityLink]:
|
||||
audio_entities: list[dict],
|
||||
video_entities: list[dict],
|
||||
image_entities: list[dict],
|
||||
document_entities: list[dict],
|
||||
) -> list[EntityLink]:
|
||||
"""
|
||||
跨模态实体对齐
|
||||
|
||||
@@ -259,7 +258,7 @@ class MultimodalEntityLinker:
|
||||
return links
|
||||
|
||||
def fuse_entity_knowledge(
|
||||
self, entity_id: str, linked_entities: List[Dict], multimodal_mentions: List[Dict]
|
||||
self, entity_id: str, linked_entities: list[dict], multimodal_mentions: list[dict]
|
||||
) -> FusionResult:
|
||||
"""
|
||||
融合多模态实体知识
|
||||
@@ -331,7 +330,7 @@ class MultimodalEntityLinker:
|
||||
confidence=min(1.0, len(linked_entities) * 0.2 + 0.5),
|
||||
)
|
||||
|
||||
def detect_entity_conflicts(self, entities: List[Dict]) -> List[Dict]:
|
||||
def detect_entity_conflicts(self, entities: list[dict]) -> list[dict]:
|
||||
"""
|
||||
检测实体冲突(同名但不同义)
|
||||
|
||||
@@ -380,7 +379,7 @@ class MultimodalEntityLinker:
|
||||
|
||||
return conflicts
|
||||
|
||||
def suggest_entity_merges(self, entities: List[Dict], existing_links: List[EntityLink] = None) -> List[Dict]:
|
||||
def suggest_entity_merges(self, entities: list[dict], existing_links: list[EntityLink] = None) -> list[dict]:
|
||||
"""
|
||||
建议实体合并
|
||||
|
||||
@@ -464,7 +463,7 @@ class MultimodalEntityLinker:
|
||||
confidence=confidence,
|
||||
)
|
||||
|
||||
def analyze_modality_distribution(self, multimodal_entities: List[MultimodalEntity]) -> Dict:
|
||||
def analyze_modality_distribution(self, multimodal_entities: list[MultimodalEntity]) -> dict:
|
||||
"""
|
||||
分析模态分布
|
||||
|
||||
|
||||
Reference in New Issue
Block a user