| 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] |
|
|
|
|
| |
| EXAMPLE_SCHEMA = GraphSchema( |
| |
| nodes=[ |
| |
| 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"}), |
| |
| NodeSchema(label="Check", properties={"name": "string"}), |
| NodeSchema(label="Department", properties={"name": "string"}), |
| NodeSchema(label="Producer", properties={"name": "string"}), |
| ], |
| |
| relationships=[ |
| |
| 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={} |
| ), |
| |
| |
| RelationshipSchema( |
| type="need_check", |
| from_node="Disease", |
| to_node="Check", |
| properties={} |
| ), |
| |
| RelationshipSchema( |
| type="belongs_to", |
| from_node="Disease", |
| to_node="Department", |
| properties={} |
| ), |
| |
| RelationshipSchema( |
| type="common_drug", |
| from_node="Disease", |
| to_node="Drug", |
| properties={} |
| ), |
| |
| RelationshipSchema( |
| type="do_eat", |
| from_node="Disease", |
| to_node="Food", |
| properties={} |
| ), |
| |
| RelationshipSchema( |
| type="no_eat", |
| from_node="Disease", |
| to_node="Food", |
| properties={} |
| ), |
| |
| RelationshipSchema( |
| type="acompany_with", |
| from_node="Disease", |
| to_node="Disease", |
| properties={} |
| ), |
| |
| RelationshipSchema( |
| type="drugs_of", |
| from_node="Producer", |
| to_node="Drug", |
| properties={} |
| ), |
| ] |
| ) |
|
|
|
|
| if __name__ == '__main__': |
| res = str(EXAMPLE_SCHEMA.model_dump()) |
| print(res) |