fix: auto-fix code issues (cron)
- 修复隐式 Optional 类型注解 (RUF013) - 修复不必要的赋值后返回 (RET504) - 优化列表推导式 (PERF401) - 修复未使用的参数 (ARG002) - 清理重复导入 - 优化异常处理
This commit is contained in:
@@ -30,7 +30,7 @@ class MultimodalEntity:
|
||||
source_id: str
|
||||
mention_context: str
|
||||
confidence: float
|
||||
modality_features: dict = None # 模态特定特征
|
||||
modality_features: dict | None = None # 模态特定特征
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if self.modality_features is None:
|
||||
@@ -137,7 +137,8 @@ class MultimodalEntityLinker:
|
||||
"""
|
||||
# 名称相似度
|
||||
name_sim = self.calculate_string_similarity(
|
||||
entity1.get("name", ""), entity2.get("name", ""),
|
||||
entity1.get("name", ""),
|
||||
entity2.get("name", ""),
|
||||
)
|
||||
|
||||
# 如果名称完全匹配
|
||||
@@ -158,7 +159,8 @@ class MultimodalEntityLinker:
|
||||
|
||||
# 定义相似度
|
||||
def_sim = self.calculate_string_similarity(
|
||||
entity1.get("definition", ""), entity2.get("definition", ""),
|
||||
entity1.get("definition", ""),
|
||||
entity2.get("definition", ""),
|
||||
)
|
||||
|
||||
# 综合相似度
|
||||
@@ -170,7 +172,10 @@ class MultimodalEntityLinker:
|
||||
return combined_sim, "none"
|
||||
|
||||
def find_matching_entity(
|
||||
self, query_entity: dict, candidate_entities: list[dict], exclude_ids: set[str] = None,
|
||||
self,
|
||||
query_entity: dict,
|
||||
candidate_entities: list[dict],
|
||||
exclude_ids: set[str] = None,
|
||||
) -> AlignmentResult | None:
|
||||
"""
|
||||
在候选实体中查找匹配的实体
|
||||
@@ -270,7 +275,10 @@ 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:
|
||||
"""
|
||||
融合多模态实体知识
|
||||
@@ -394,7 +402,9 @@ class MultimodalEntityLinker:
|
||||
return conflicts
|
||||
|
||||
def suggest_entity_merges(
|
||||
self, entities: list[dict], existing_links: list[EntityLink] = None,
|
||||
self,
|
||||
entities: list[dict],
|
||||
existing_links: list[EntityLink] = None,
|
||||
) -> list[dict]:
|
||||
"""
|
||||
建议实体合并
|
||||
@@ -510,9 +520,9 @@ class MultimodalEntityLinker:
|
||||
"total_multimodal_records": len(multimodal_entities),
|
||||
"unique_entities": len(entity_modalities),
|
||||
"cross_modal_entities": cross_modal_count,
|
||||
"cross_modal_ratio": cross_modal_count / len(entity_modalities)
|
||||
if entity_modalities
|
||||
else 0,
|
||||
"cross_modal_ratio": (
|
||||
cross_modal_count / len(entity_modalities) if entity_modalities else 0
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user