(entity_list, entity_label, aliases=None)
| 76 | } |
| 77 | |
| 78 | def _store_entity(entity_list, entity_label, aliases=None): |
| 79 | for entity in entity_list: |
| 80 | entity_id = entity.node_id |
| 81 | entity_name = entity.name or f"{entity_label}_{entity_id}" |
| 82 | |
| 83 | props = getattr(entity, "properties", {}) |
| 84 | display_label = label_display.get(entity_label, entity_label) |
| 85 | content_parts = [f"{display_label}名称: {entity_name}"] |
| 86 | if props.get("description"): |
| 87 | content_parts.append(f"描述: {props['description']}") |
| 88 | if props.get("category"): |
| 89 | content_parts.append(f"分类: {props['category']}") |
| 90 | if props.get("severity"): |
| 91 | content_parts.append(f"严重程度: {props['severity']}") |
| 92 | if props.get("tags"): |
| 93 | content_parts.append(f"标签: {props['tags']}") |
| 94 | if props.get("methods"): |
| 95 | content_parts.append(f"方法: {props['methods']}") |
| 96 | if props.get("dosage"): |
| 97 | content_parts.append(f"剂量: {props['dosage']}") |
| 98 | |
| 99 | entity_kv = EntityKeyValue( |
| 100 | entity_name=entity_name, |
| 101 | index_keys=[entity_name], |
| 102 | value_content="\n".join(content_parts), |
| 103 | entity_type=entity_label, |
| 104 | metadata={ |
| 105 | "node_id": entity_id, |
| 106 | "properties": props |
| 107 | } |
| 108 | ) |
| 109 | |
| 110 | self.entity_kv_store[entity_id] = entity_kv |
| 111 | self.key_to_entities[entity_name].append(entity_id) |
| 112 | if aliases: |
| 113 | alias_values = aliases(entity) or [] |
| 114 | if isinstance(alias_values, str): |
| 115 | alias_values = [alias_values] |
| 116 | for alias in alias_values: |
| 117 | if alias and alias != entity_name: |
| 118 | self.key_to_entities[alias].append(entity_id) |
| 119 | |
| 120 | _store_entity(diseases, "Disease", aliases=lambda e: e.properties.get("aliases", [])) |
| 121 | _store_entity(symptoms, "Symptom") |
nothing calls this directly
no test coverage detected