KnowledgeGraphDTO.java 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. package com.lingyue.graph.dto;
  2. import io.swagger.v3.oas.annotations.media.Schema;
  3. import lombok.Data;
  4. import lombok.Builder;
  5. import lombok.NoArgsConstructor;
  6. import lombok.AllArgsConstructor;
  7. import java.util.List;
  8. import java.util.Map;
  9. /**
  10. * 知识图谱 DTO
  11. * 用于前端图谱可视化渲染
  12. *
  13. * @author lingyue
  14. * @since 2026-01-21
  15. */
  16. @Data
  17. @Builder
  18. @NoArgsConstructor
  19. @AllArgsConstructor
  20. @Schema(description = "知识图谱")
  21. public class KnowledgeGraphDTO {
  22. @Schema(description = "文档ID(单文档图谱时)")
  23. private String documentId;
  24. @Schema(description = "图谱标题")
  25. private String title;
  26. @Schema(description = "节点列表")
  27. private List<NodeDTO> nodes;
  28. @Schema(description = "关系/边列表")
  29. private List<EdgeDTO> edges;
  30. @Schema(description = "统计信息")
  31. private GraphStats stats;
  32. /**
  33. * 节点 DTO
  34. */
  35. @Data
  36. @Builder
  37. @NoArgsConstructor
  38. @AllArgsConstructor
  39. @Schema(description = "图谱节点")
  40. public static class NodeDTO {
  41. @Schema(description = "节点ID")
  42. private String id;
  43. @Schema(description = "节点名称(显示文本)")
  44. private String name;
  45. @Schema(description = "节点类型", example = "entity/concept/data/location/person/org")
  46. private String type;
  47. @Schema(description = "显示图标(emoji)")
  48. private String icon;
  49. @Schema(description = "节点颜色")
  50. private String color;
  51. @Schema(description = "节点大小(基于关联数量)")
  52. private Integer size;
  53. @Schema(description = "关联实体数量")
  54. private Integer relationCount;
  55. @Schema(description = "在文档中出现次数")
  56. private Integer occurrenceCount;
  57. @Schema(description = "节点值(如数据类型的具体值)")
  58. private String value;
  59. @Schema(description = "来源文档ID列表")
  60. private List<String> documentIds;
  61. @Schema(description = "位置信息")
  62. private Map<String, Object> position;
  63. @Schema(description = "元数据")
  64. private Map<String, Object> metadata;
  65. }
  66. /**
  67. * 边/关系 DTO
  68. */
  69. @Data
  70. @Builder
  71. @NoArgsConstructor
  72. @AllArgsConstructor
  73. @Schema(description = "图谱边/关系")
  74. public static class EdgeDTO {
  75. @Schema(description = "边ID")
  76. private String id;
  77. @Schema(description = "源节点ID")
  78. private String source;
  79. @Schema(description = "源节点名称")
  80. private String sourceName;
  81. @Schema(description = "目标节点ID")
  82. private String target;
  83. @Schema(description = "目标节点名称")
  84. private String targetName;
  85. @Schema(description = "关系类型", example = "属于/包含/位于/负责")
  86. private String relationType;
  87. @Schema(description = "关系标签(显示文本)")
  88. private String label;
  89. @Schema(description = "边的权重/强度")
  90. private Double weight;
  91. @Schema(description = "元数据")
  92. private Map<String, Object> metadata;
  93. }
  94. /**
  95. * 图谱统计
  96. */
  97. @Data
  98. @Builder
  99. @NoArgsConstructor
  100. @AllArgsConstructor
  101. @Schema(description = "图谱统计")
  102. public static class GraphStats {
  103. @Schema(description = "总节点数")
  104. private Integer totalNodes;
  105. @Schema(description = "总关系数")
  106. private Integer totalEdges;
  107. @Schema(description = "按类型统计节点数")
  108. private Map<String, Integer> nodesByType;
  109. @Schema(description = "按类型统计关系数")
  110. private Map<String, Integer> edgesByType;
  111. }
  112. /**
  113. * 实体列表项 DTO(用于列表视图)
  114. */
  115. @Data
  116. @Builder
  117. @NoArgsConstructor
  118. @AllArgsConstructor
  119. @Schema(description = "实体列表项")
  120. public static class EntityListItemDTO {
  121. @Schema(description = "实体ID")
  122. private String id;
  123. @Schema(description = "实体名称")
  124. private String name;
  125. @Schema(description = "实体类型")
  126. private String type;
  127. @Schema(description = "类型显示名称")
  128. private String typeName;
  129. @Schema(description = "图标")
  130. private String icon;
  131. @Schema(description = "颜色")
  132. private String color;
  133. @Schema(description = "出现次数")
  134. private Integer occurrenceCount;
  135. @Schema(description = "关联实体数量")
  136. private Integer relationCount;
  137. @Schema(description = "关联实体预览(前几个)")
  138. private List<RelatedEntityDTO> relatedEntities;
  139. }
  140. /**
  141. * 关联实体预览
  142. */
  143. @Data
  144. @Builder
  145. @NoArgsConstructor
  146. @AllArgsConstructor
  147. @Schema(description = "关联实体")
  148. public static class RelatedEntityDTO {
  149. @Schema(description = "实体ID")
  150. private String id;
  151. @Schema(description = "实体名称")
  152. private String name;
  153. @Schema(description = "关系类型")
  154. private String relationType;
  155. }
  156. /**
  157. * 实体列表分组
  158. */
  159. @Data
  160. @Builder
  161. @NoArgsConstructor
  162. @AllArgsConstructor
  163. @Schema(description = "实体列表分组")
  164. public static class EntityGroupDTO {
  165. @Schema(description = "分组类型")
  166. private String type;
  167. @Schema(description = "分组名称")
  168. private String typeName;
  169. @Schema(description = "分组颜色")
  170. private String color;
  171. @Schema(description = "实体数量")
  172. private Integer count;
  173. @Schema(description = "实体列表")
  174. private List<EntityListItemDTO> entities;
  175. }
  176. /**
  177. * 实体详情
  178. */
  179. @Data
  180. @Builder
  181. @NoArgsConstructor
  182. @AllArgsConstructor
  183. @Schema(description = "实体详情")
  184. public static class EntityDetailDTO {
  185. @Schema(description = "实体ID")
  186. private String id;
  187. @Schema(description = "实体名称")
  188. private String name;
  189. @Schema(description = "实体类型")
  190. private String type;
  191. @Schema(description = "类型显示名称")
  192. private String typeName;
  193. @Schema(description = "实体值")
  194. private String value;
  195. @Schema(description = "图标")
  196. private String icon;
  197. @Schema(description = "颜色")
  198. private String color;
  199. @Schema(description = "出现次数")
  200. private Integer occurrenceCount;
  201. @Schema(description = "所有关联实体")
  202. private List<RelatedEntityDTO> allRelations;
  203. @Schema(description = "出现位置列表")
  204. private List<OccurrenceDTO> occurrences;
  205. @Schema(description = "来源文档列表")
  206. private List<DocumentRefDTO> documents;
  207. @Schema(description = "元数据")
  208. private Map<String, Object> metadata;
  209. }
  210. /**
  211. * 出现位置
  212. */
  213. @Data
  214. @Builder
  215. @NoArgsConstructor
  216. @AllArgsConstructor
  217. @Schema(description = "出现位置")
  218. public static class OccurrenceDTO {
  219. @Schema(description = "文档ID")
  220. private String documentId;
  221. @Schema(description = "文档名称")
  222. private String documentName;
  223. @Schema(description = "上下文片段")
  224. private String context;
  225. @Schema(description = "位置信息")
  226. private Map<String, Object> position;
  227. }
  228. /**
  229. * 文档引用
  230. */
  231. @Data
  232. @Builder
  233. @NoArgsConstructor
  234. @AllArgsConstructor
  235. @Schema(description = "文档引用")
  236. public static class DocumentRefDTO {
  237. @Schema(description = "文档ID")
  238. private String documentId;
  239. @Schema(description = "文档名称")
  240. private String documentName;
  241. @Schema(description = "在该文档中的出现次数")
  242. private Integer count;
  243. }
  244. }