SGTY 2 kuukautta sitten
vanhempi
commit
101322cce8

+ 20 - 0
src/test/java/com/qizhen/healsphere/OllamaBGE.java

@@ -0,0 +1,20 @@
+package com.qizhen.healsphere;
+
+import java.net.URI;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.http.Method;
+import com.alibaba.fastjson.JSON;
+
+public class OllamaBGE {
+    public static void main(String[] args) {
+        String url = "http://172.16.8.98:11434/api/embeddings";
+        String jsonBody = "{\"model\": \"bge-m3\", \"prompt\": \"需要向量化的文本\"}";
+
+        HttpRequest request = HttpUtil.createRequest(Method.POST, url)
+                .header("Content-Type", "application/json")
+                .body(jsonBody);
+        String body = request.execute().body();
+        System.out.println(JSON.parseObject(body).getJSONArray("embedding").size());
+    }
+}

+ 93 - 0
src/test/java/com/qizhen/healsphere/SnomedCTFromExcelTest.java

@@ -0,0 +1,93 @@
+package com.qizhen.healsphere;
+
+import com.qizhen.healsphere.repository.neo4j.entity.BaseEntity;
+import com.qizhen.healsphere.service.EntityService;
+import com.qizhen.healsphere.service.RelationshipService;
+import com.qizhen.healsphere.web.vo.CreateEntityVO;
+import com.qizhen.healsphere.web.vo.RelationshipVO;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * 是否空腹及归大类
+ */
+@RunWith(SpringRunner.class)
+@ComponentScan(basePackages = {"com.qizhen.healsphere.model", "com.qizhen.healsphere.repository"})
+@SpringBootTest
+public class SnomedCTFromExcelTest {
+    @Autowired
+    RelationshipService relationshipService;
+    @Autowired
+    EntityService entityService;
+    private static String urlExcelPath = "C:\\Users\\17664\\Desktop\\data2(1).xlsx";
+
+    @Test
+    public void WriteFromExcel() throws Exception {
+        getDataFromExecl(0);
+    }
+
+    private void getDataFromExecl(int index) throws Exception {
+        InputStream fis = new FileInputStream(urlExcelPath);
+        Workbook urlWorkbook = WorkbookFactory.create(fis);
+        Sheet urlSheet = urlWorkbook.getSheetAt(index);
+
+        for (int rowNum = 0; rowNum <= urlSheet.getLastRowNum(); rowNum++) {
+            try {
+                Map<String, String> map = new HashMap<>();
+                Row row = urlSheet.getRow(rowNum);
+                saveNeo4j(row.getCell(0).getStringCellValue().trim(), row.getCell(1).getStringCellValue().trim(), row.getCell(2).getStringCellValue().trim(), row.getCell(3).getStringCellValue().trim(), row.getCell(4).getStringCellValue().trim());
+            } catch (Exception e) {
+            }
+        }
+    }
+
+    private void saveNeo4j(String startName, String startLabel, String relationShip, String endName, String endLabel) throws Exception {
+        try {
+            if(StringUtils.isEmpty(startName) || StringUtils.isEmpty(startLabel)|| StringUtils.isEmpty(relationShip)|| StringUtils.isEmpty(endName) || StringUtils.isEmpty(endLabel)){
+                return;
+            }
+            BaseEntity startEntity = createNoExists(startLabel, startName);
+            long startId = startEntity.getId();
+            BaseEntity endEntity = createNoExists(endLabel, endName);
+            Long endId = endEntity.getId();
+            RelationshipVO relationshipVO = new RelationshipVO();
+            relationshipVO.setStartId(startId);
+            relationshipVO.setEndId(endId);
+            relationshipVO.setStartLabel(startLabel);
+            relationshipVO.setEndLabel(endLabel);
+            relationshipVO.setRelationshipType(relationShip);
+            System.out.println(relationshipService.createRelationship(Arrays.asList(relationshipVO)));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private BaseEntity createNoExists(String labelName, String name) {
+        BaseEntity nodeByName = entityService.findNodeByName(labelName, name);
+        if (Objects.nonNull(nodeByName)) {//节点不存在
+            return nodeByName;
+        }
+        CreateEntityVO createEntity = new CreateEntityVO();
+        createEntity.setName(name);
+        createEntity.setLabel(labelName);
+        return entityService.create(createEntity);
+    }
+
+}
+