"""沿人工标注关系找受供应商事件影响的产品；不是自动图抽取或 GraphRAG 框架。"""
# 每条边都携带来源，关系不是模型猜测的事实。
edges = [
    ("P-204", "supplied_by", "S-8", "product-manual-v1"),
    ("P-205", "supplied_by", "S-9", "product-manual-v1"),
    ("S-8", "affected_by", "E-1", "supplier-notice-v1"),
]
# 假设这些来源已在本次授权范围内，实际服务必须从登录态构造该集合。
allowed_sources = {"product-manual-v1", "supplier-notice-v1"}
visible = [edge for edge in edges if edge[3] in allowed_sources]
affected_suppliers = {source for source, relation, target, doc in visible
                      if relation == "affected_by" and target == "E-1"}
answers = []
for source, relation, target, doc in visible:
    if relation == "supplied_by" and target in affected_suppliers:
        # 保存两跳来源，不让图上的一条推导结论失去原文依据。
        notice = [d for s, rel, t, d in visible if s == target and rel == "affected_by" and t == "E-1"]
        answers.append({"product": source, "sources": [doc, *notice]})
print(answers)
# 关系只说明供应链关联；是否所有批次均受影响还需要公告范围与批次事实。
