| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- package com.lingyue.graph.dto;
- import io.swagger.v3.oas.annotations.media.Schema;
- import lombok.Data;
- import lombok.Builder;
- import lombok.NoArgsConstructor;
- import lombok.AllArgsConstructor;
- import java.util.List;
- import java.util.Map;
- /**
- * 知识图谱 DTO
- * 用于前端图谱可视化渲染
- *
- * @author lingyue
- * @since 2026-01-21
- */
- @Data
- @Builder
- @NoArgsConstructor
- @AllArgsConstructor
- @Schema(description = "知识图谱")
- public class KnowledgeGraphDTO {
-
- @Schema(description = "文档ID(单文档图谱时)")
- private String documentId;
-
- @Schema(description = "图谱标题")
- private String title;
-
- @Schema(description = "节点列表")
- private List<NodeDTO> nodes;
-
- @Schema(description = "关系/边列表")
- private List<EdgeDTO> edges;
-
- @Schema(description = "统计信息")
- private GraphStats stats;
-
- /**
- * 节点 DTO
- */
- @Data
- @Builder
- @NoArgsConstructor
- @AllArgsConstructor
- @Schema(description = "图谱节点")
- public static class NodeDTO {
-
- @Schema(description = "节点ID")
- private String id;
-
- @Schema(description = "节点名称(显示文本)")
- private String name;
-
- @Schema(description = "节点类型", example = "entity/concept/data/location/person/org")
- private String type;
-
- @Schema(description = "显示图标(emoji)")
- private String icon;
-
- @Schema(description = "节点颜色")
- private String color;
-
- @Schema(description = "节点大小(基于关联数量)")
- private Integer size;
-
- @Schema(description = "关联实体数量")
- private Integer relationCount;
-
- @Schema(description = "在文档中出现次数")
- private Integer occurrenceCount;
-
- @Schema(description = "节点值(如数据类型的具体值)")
- private String value;
-
- @Schema(description = "来源文档ID列表")
- private List<String> documentIds;
-
- @Schema(description = "位置信息")
- private Map<String, Object> position;
-
- @Schema(description = "元数据")
- private Map<String, Object> metadata;
- }
-
- /**
- * 边/关系 DTO
- */
- @Data
- @Builder
- @NoArgsConstructor
- @AllArgsConstructor
- @Schema(description = "图谱边/关系")
- public static class EdgeDTO {
-
- @Schema(description = "边ID")
- private String id;
-
- @Schema(description = "源节点ID")
- private String source;
-
- @Schema(description = "源节点名称")
- private String sourceName;
-
- @Schema(description = "目标节点ID")
- private String target;
-
- @Schema(description = "目标节点名称")
- private String targetName;
-
- @Schema(description = "关系类型", example = "属于/包含/位于/负责")
- private String relationType;
-
- @Schema(description = "关系标签(显示文本)")
- private String label;
-
- @Schema(description = "边的权重/强度")
- private Double weight;
-
- @Schema(description = "元数据")
- private Map<String, Object> metadata;
- }
-
- /**
- * 图谱统计
- */
- @Data
- @Builder
- @NoArgsConstructor
- @AllArgsConstructor
- @Schema(description = "图谱统计")
- public static class GraphStats {
-
- @Schema(description = "总节点数")
- private Integer totalNodes;
-
- @Schema(description = "总关系数")
- private Integer totalEdges;
-
- @Schema(description = "按类型统计节点数")
- private Map<String, Integer> nodesByType;
-
- @Schema(description = "按类型统计关系数")
- private Map<String, Integer> edgesByType;
- }
-
- /**
- * 实体列表项 DTO(用于列表视图)
- */
- @Data
- @Builder
- @NoArgsConstructor
- @AllArgsConstructor
- @Schema(description = "实体列表项")
- public static class EntityListItemDTO {
-
- @Schema(description = "实体ID")
- private String id;
-
- @Schema(description = "实体名称")
- private String name;
-
- @Schema(description = "实体类型")
- private String type;
-
- @Schema(description = "类型显示名称")
- private String typeName;
-
- @Schema(description = "图标")
- private String icon;
-
- @Schema(description = "颜色")
- private String color;
-
- @Schema(description = "出现次数")
- private Integer occurrenceCount;
-
- @Schema(description = "关联实体数量")
- private Integer relationCount;
-
- @Schema(description = "关联实体预览(前几个)")
- private List<RelatedEntityDTO> relatedEntities;
- }
-
- /**
- * 关联实体预览
- */
- @Data
- @Builder
- @NoArgsConstructor
- @AllArgsConstructor
- @Schema(description = "关联实体")
- public static class RelatedEntityDTO {
-
- @Schema(description = "实体ID")
- private String id;
-
- @Schema(description = "实体名称")
- private String name;
-
- @Schema(description = "关系类型")
- private String relationType;
- }
-
- /**
- * 实体列表分组
- */
- @Data
- @Builder
- @NoArgsConstructor
- @AllArgsConstructor
- @Schema(description = "实体列表分组")
- public static class EntityGroupDTO {
-
- @Schema(description = "分组类型")
- private String type;
-
- @Schema(description = "分组名称")
- private String typeName;
-
- @Schema(description = "分组颜色")
- private String color;
-
- @Schema(description = "实体数量")
- private Integer count;
-
- @Schema(description = "实体列表")
- private List<EntityListItemDTO> entities;
- }
-
- /**
- * 实体详情
- */
- @Data
- @Builder
- @NoArgsConstructor
- @AllArgsConstructor
- @Schema(description = "实体详情")
- public static class EntityDetailDTO {
-
- @Schema(description = "实体ID")
- private String id;
-
- @Schema(description = "实体名称")
- private String name;
-
- @Schema(description = "实体类型")
- private String type;
-
- @Schema(description = "类型显示名称")
- private String typeName;
-
- @Schema(description = "实体值")
- private String value;
-
- @Schema(description = "图标")
- private String icon;
-
- @Schema(description = "颜色")
- private String color;
-
- @Schema(description = "出现次数")
- private Integer occurrenceCount;
-
- @Schema(description = "所有关联实体")
- private List<RelatedEntityDTO> allRelations;
-
- @Schema(description = "出现位置列表")
- private List<OccurrenceDTO> occurrences;
-
- @Schema(description = "来源文档列表")
- private List<DocumentRefDTO> documents;
-
- @Schema(description = "元数据")
- private Map<String, Object> metadata;
- }
-
- /**
- * 出现位置
- */
- @Data
- @Builder
- @NoArgsConstructor
- @AllArgsConstructor
- @Schema(description = "出现位置")
- public static class OccurrenceDTO {
-
- @Schema(description = "文档ID")
- private String documentId;
-
- @Schema(description = "文档名称")
- private String documentName;
-
- @Schema(description = "上下文片段")
- private String context;
-
- @Schema(description = "位置信息")
- private Map<String, Object> position;
- }
-
- /**
- * 文档引用
- */
- @Data
- @Builder
- @NoArgsConstructor
- @AllArgsConstructor
- @Schema(description = "文档引用")
- public static class DocumentRefDTO {
-
- @Schema(description = "文档ID")
- private String documentId;
-
- @Schema(description = "文档名称")
- private String documentName;
-
- @Schema(description = "在该文档中的出现次数")
- private Integer count;
- }
- }
|