File size: 3,547 Bytes
8a17806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
from pydantic import BaseModel
from typing import Dict, List, Optional


class NodeSchema(BaseModel):
    label: str
    properties: Dict[str, str]  # 属性名: 类型


class RelationshipSchema(BaseModel):
    type: str
    from_node: str              # 起始节点标签
    to_node: str                # 目标节点标签
    properties: Dict[str, str]  # 属性名: 类型


class GraphSchema(BaseModel):
    nodes: List[NodeSchema]
    relationships: List[RelationshipSchema]


# 示例图模式 (按照neo4j数据库中的定义schema来填充)
EXAMPLE_SCHEMA = GraphSchema(
    # 节点的名称一定要严格保持跟neo4j一致
    nodes=[
        # --- PDF 原有的 4 个节点 ---
        NodeSchema(label="Disease", properties={"name": "string", "desc": "string", "cause": "string", "prevent": "string", "cure_lasttime": "string", "cure_department": "string", "cure_way": "string", "cure_prob": "string", "easy_get": "string"}),
        NodeSchema(label="Drug", properties={"name": "string"}),
        NodeSchema(label="Food", properties={"name": "string"}),
        NodeSchema(label="Symptom", properties={"name": "string"}),
        # --- 基于 Neo4j 截图新增的 3 个节点 ---
        NodeSchema(label="Check", properties={"name": "string"}),
        NodeSchema(label="Department", properties={"name": "string"}),
        NodeSchema(label="Producer", properties={"name": "string"}),
    ],
    # 关系的相关字段一定要严格保持跟neo4j一致, 大小写都不能错
    relationships=[
        # --- PDF 原有的 3 个关系 ---
        RelationshipSchema(
            type="has_symptom",
            from_node="Disease",
            to_node="Symptom",
            properties={}
        ),
        RelationshipSchema(
            type="recommand_drug",
            from_node="Disease",
            to_node="Drug",
            properties={}
        ),
        RelationshipSchema(
            type="recommand_eat",
            from_node="Disease",
            to_node="Food",
            properties={}
        ),
        # --- 基于 Neo4j 截图新增的关系 ---
        # Disease 需要做的检查项目
        RelationshipSchema(
            type="need_check",
            from_node="Disease",
            to_node="Check",
            properties={}
        ),
        # Disease 所属的科室
        RelationshipSchema(
            type="belongs_to",
            from_node="Disease",
            to_node="Department",
            properties={}
        ),
        # Disease 的常用药物
        RelationshipSchema(
            type="common_drug",
            from_node="Disease",
            to_node="Drug",
            properties={}
        ),
        # Disease 宜吃的食物
        RelationshipSchema(
            type="do_eat",
            from_node="Disease",
            to_node="Food",
            properties={}
        ),
        # Disease 忌吃的食物
        RelationshipSchema(
            type="no_eat",
            from_node="Disease",
            to_node="Food",
            properties={}
        ),
        # Disease 的并发症
        RelationshipSchema(
            type="acompany_with",
            from_node="Disease",
            to_node="Disease",
            properties={}
        ),
        # Drug 的生产商
        RelationshipSchema(
            type="drugs_of",
            from_node="Producer",
            to_node="Drug",
            properties={}
        ),
    ]
)


if __name__ == '__main__':
    res = str(EXAMPLE_SCHEMA.model_dump())
    print(res)