|
@@ -4,13 +4,19 @@ import com.diagbot.dto.BaseNodeDTO;
|
|
import com.diagbot.dto.BaseNodeRSDTO;
|
|
import com.diagbot.dto.BaseNodeRSDTO;
|
|
import com.diagbot.dto.CategorieDTO;
|
|
import com.diagbot.dto.CategorieDTO;
|
|
import com.diagbot.dto.GNodeDTO;
|
|
import com.diagbot.dto.GNodeDTO;
|
|
|
|
+import com.diagbot.dto.Categories;
|
|
|
|
+import com.diagbot.dto.GraDTO;
|
|
import com.diagbot.dto.GraphDTO;
|
|
import com.diagbot.dto.GraphDTO;
|
|
import com.diagbot.dto.GraphLabelDTO;
|
|
import com.diagbot.dto.GraphLabelDTO;
|
|
import com.diagbot.dto.LinkDTO;
|
|
import com.diagbot.dto.LinkDTO;
|
|
|
|
+import com.diagbot.dto.Link;
|
|
|
|
+import com.diagbot.dto.Node;
|
|
import com.diagbot.dto.TreeDTO;
|
|
import com.diagbot.dto.TreeDTO;
|
|
|
|
+import com.diagbot.dto.Tu;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
import com.diagbot.exception.CommonException;
|
|
import com.diagbot.exception.CommonException;
|
|
import com.diagbot.service.impl.KgServiceImpl;
|
|
import com.diagbot.service.impl.KgServiceImpl;
|
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
import com.diagbot.util.FastJsonUtils;
|
|
import com.diagbot.util.FastJsonUtils;
|
|
import com.diagbot.util.ListUtil;
|
|
import com.diagbot.util.ListUtil;
|
|
import com.diagbot.vo.KgQueryVO;
|
|
import com.diagbot.vo.KgQueryVO;
|
|
@@ -19,6 +25,7 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -140,4 +147,63 @@ public class KgFacade extends KgServiceImpl {
|
|
"\t }\n" +
|
|
"\t }\n" +
|
|
" ]\n" +
|
|
" ]\n" +
|
|
"}";
|
|
"}";
|
|
|
|
+ private void addNode(TreeDTO treeDTO) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public GraDTO getTuFac(KgQueryVO kgQueryVO) {
|
|
|
|
+ GraDTO graDTO = new GraDTO();
|
|
|
|
+ List<Tu> tu = this.getTu(kgQueryVO);
|
|
|
|
+ Map<String, List<Tu>> map = EntityUtil.makeEntityListMap(tu, "rel");
|
|
|
|
+
|
|
|
|
+ List<Categories> categoriesList = new ArrayList<>();
|
|
|
|
+ List<Node> nodeList = new ArrayList<>();
|
|
|
|
+ List<Link> linksList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ // 添加第一个节点:中心节点
|
|
|
|
+ Node node = new Node(0, kgQueryVO.getInputStr(), 0L, 50);
|
|
|
|
+ nodeList.add(node);
|
|
|
|
+
|
|
|
|
+ // 设置categories
|
|
|
|
+ Map<String, Integer> relMap = new LinkedHashMap<>();
|
|
|
|
+ int i = 0; // 设置category
|
|
|
|
+ Categories c1 = new Categories("中心词");
|
|
|
|
+ categoriesList.add(c1);
|
|
|
|
+ relMap.put("中心词", i++);
|
|
|
|
+ Categories c2 = new Categories("关系");
|
|
|
|
+ categoriesList.add(c2);
|
|
|
|
+ relMap.put("关系", i++);
|
|
|
|
+ Long j = 1L; // 设置节点编号
|
|
|
|
+ for (String key : map.keySet()) {
|
|
|
|
+ Categories bean = new Categories(key);
|
|
|
|
+ categoriesList.add(bean);
|
|
|
|
+ relMap.put(key, i);
|
|
|
|
+
|
|
|
|
+ // 添加关系节点
|
|
|
|
+ Node nodeRel = new Node(1, "", j, 10);
|
|
|
|
+ nodeList.add(nodeRel);
|
|
|
|
+
|
|
|
|
+ // 添加中心节点与关系的关联
|
|
|
|
+ Link linkRel = new Link(0L, j, key);
|
|
|
|
+ linksList.add(linkRel);
|
|
|
|
+
|
|
|
|
+ List<Tu> inner = map.get(key);
|
|
|
|
+ for (Tu t : inner) {
|
|
|
|
+ // 添加关系下的节点
|
|
|
|
+ Node nodeLabel = new Node(i, t.getSubName(), ++j, 28);
|
|
|
|
+ nodeList.add(nodeLabel);
|
|
|
|
+
|
|
|
|
+ // 添加关系和节点的关联
|
|
|
|
+ Link linkLabel = new Link(linkRel.getTarget(), j, "");
|
|
|
|
+ linksList.add(linkLabel);
|
|
|
|
+ }
|
|
|
|
+ i++;
|
|
|
|
+ j++;
|
|
|
|
+ }
|
|
|
|
+ graDTO.setCategoriesList(categoriesList);
|
|
|
|
+ graDTO.setNodeList(nodeList);
|
|
|
|
+ graDTO.setLinksList(linksList);
|
|
|
|
+
|
|
|
|
+ return graDTO;
|
|
|
|
+ }
|
|
}
|
|
}
|