You've already forked DataMate
- 实现三层对齐策略:规则层 + 向量相似度层 + LLM 仲裁层 - 规则层:名称规范化(NFKC、小写、去标点/空格)+ 规则评分 - 向量层:OpenAI Embeddings + cosine 相似度计算 - LLM 层:仅对边界样本调用,严格 JSON schema 校验 - 使用 Union-Find 实现传递合并 - 支持批内对齐(库内对齐待 KG 服务 API 支持) 核心组件: - EntityAligner 类:align() (async)、align_rules_only() (sync) - 配置项:kg_alignment_enabled(默认 false)、embedding_model、阈值 - 失败策略:fail-open(对齐失败不中断请求) 集成: - 已集成到抽取主链路(extract → align → return) - extract() 调用 async align() - extract_sync() 调用 sync align_rules_only() 修复: - P1-1:使用 (name, type) 作为 key,避免同名跨类型误合并 - P1-2:LLM 计数在 finally 块中增加,异常也计数 - P1-3:添加库内对齐说明(待后续实现) 新增 41 个测试用例,全部通过 测试结果:41 tests pass
22 lines
497 B
Python
22 lines
497 B
Python
from app.module.kg_extraction.aligner import EntityAligner
|
|
from app.module.kg_extraction.extractor import KnowledgeGraphExtractor
|
|
from app.module.kg_extraction.models import (
|
|
ExtractionRequest,
|
|
ExtractionResult,
|
|
Triple,
|
|
GraphNode,
|
|
GraphEdge,
|
|
)
|
|
from app.module.kg_extraction.interface import router
|
|
|
|
__all__ = [
|
|
"EntityAligner",
|
|
"KnowledgeGraphExtractor",
|
|
"ExtractionRequest",
|
|
"ExtractionResult",
|
|
"Triple",
|
|
"GraphNode",
|
|
"GraphEdge",
|
|
"router",
|
|
]
|