Browse Source

文本相似度

zhoutg 4 years ago
parent
commit
09c5d6acaa

+ 1 - 1
src/main/java/com/diagbot/facade/CommonFacade.java

@@ -115,7 +115,7 @@ public class CommonFacade {
     }
 
     //把图谱返回的标准词set到label中
-    public void dataTypeSet(WordCrfDTO wordCrfDTO, Map<Integer, Map<String, String>> map){
+    public void dataTypeSet(WordCrfDTO wordCrfDTO, Map<String, Map<String, String>> map){
         ChiefLabel chiefLabel = wordCrfDTO.getChiefLabel();
         PresentLabel presentLabel = wordCrfDTO.getPresentLabel();
         PastLabel pastLabel = wordCrfDTO.getPastLabel();

+ 1 - 1
src/main/java/com/diagbot/facade/IndicationFacade.java

@@ -43,7 +43,7 @@ public class IndicationFacade {
         // 标准词转换
         long l2 = System.currentTimeMillis();
         StandConvert standConvert = commonFacade.dataTypeGet(wordCrfDTO);
-        Map<Integer, Map<String, String>> standConvertMap = neoFacade.standConvert(standConvert);
+        Map<String, Map<String, String>> standConvertMap = neoFacade.standConvert(standConvert);
         commonFacade.dataTypeSet(wordCrfDTO, standConvertMap);
         CoreUtil.getDubugStr(l2, "同义词转换", res.getDubugStr());
 

+ 43 - 5
src/main/java/com/diagbot/facade/NeoFacade.java

@@ -71,6 +71,44 @@ public class NeoFacade {
             }
         }
 
+        // TODO 测试数据
+        res.put("泰舒达类", Arrays.asList("泰舒达"));
+        res.put("青霉素类", Arrays.asList("青霉素"));
+
+        return res;
+    }
+
+
+    /**
+     * 返回文本相似度匹配需要的词性列表
+     *
+     * @return
+     */
+    @Cacheable(value = "cache", key = "'similarCache'")
+    public Map<String, List<String>> getSimilarCache() {
+        Map<String, List<String>> res = new HashMap<>();
+
+        Iterator<Medicine_Code> iterator = medicineCodeRepository.findAll().iterator();
+        Medicine_Code current;
+        String med_code, med_type;
+        List<OralMedicine> sets;
+
+        while (iterator.hasNext()) {
+            current = iterator.next();
+            if (current.getMedicine_related_chem().size()>0) {
+                sets = new ArrayList<>(current.getMedicine_related_chem());
+                med_code = current.getName();
+                med_type = sets.get(0).getName();
+                if (res.get(med_type)==null) {
+                    res.put(med_type, new ArrayList<>());
+                }
+                if (res.get(med_type).indexOf(med_code)==-1) {
+                    res.get(med_type).add(med_code);
+                }
+            }
+        }
+
+        // TODO 测试数据
         res.put("泰舒达类", Arrays.asList("泰舒达"));
         res.put("青霉素类", Arrays.asList("青霉素"));
 
@@ -248,15 +286,15 @@ public class NeoFacade {
      *
      * @return  Map<String, Map<String, String>> -->Map<类型, Map<原始词, 标准词>>
      */
-    public Map<Integer, Map<String, String>> standConvert(StandConvert standConvert) {
-        Map<Integer, Map<String, String>> map = new LinkedHashMap<>();
+    public Map<String, Map<String, String>> standConvert(StandConvert standConvert) {
+        Map<String, Map<String, String>> map = new LinkedHashMap<>();
 
         /* 文本相似度模型 */
         ModelAI modelAI = new ModelAI();
 
         List<String> list = standConvert.getClinicalList();
-        Map<String, String > clinicalMap = getStandConvertTypeMap(modelAI, list, "chief_present");
-        map.put(StandConvertEnum.clinical.getKey(), clinicalMap);
+        Map<String, String> clinicalMap = getStandConvertTypeMap(modelAI, list, "chief_present");
+        map.put(StandConvertEnum.clinical.getName(), clinicalMap);
 
         return map;
     }
@@ -272,7 +310,7 @@ public class NeoFacade {
     public Map<String, String> getStandConvertTypeMap(ModelAI modelAI, List<String> list, String modelName) {
         Map<String, String> map = new LinkedHashMap<>();
         for (String s : list) {
-            JSONArray jsonArray = modelAI.loadChiefPresentSimilarAI(s, list,
+            JSONArray jsonArray = modelAI.loadSimilarAI(s, list,
                     false, modelName, chiefPresentSimilarityServiceClient);
             putMap(jsonArray, s, map);
         }

+ 35 - 6
src/main/java/com/diagbot/facade/PushFacade.java

@@ -1,6 +1,7 @@
 package com.diagbot.facade;
 
 import com.diagbot.biz.push.entity.Item;
+import com.diagbot.dto.PushBaseDTO;
 import com.diagbot.dto.PushDTO;
 import com.diagbot.dto.WordCrfDTO;
 import com.diagbot.util.ListUtil;
@@ -13,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -42,7 +44,7 @@ public class PushFacade {
 
         // 标准词转换
         StandConvert standConvert = commonFacade.dataTypeGet(wordCrfDTO);
-        Map<Integer, Map<String, String>> standConvertMap = neoFacade.standConvert(standConvert);
+        Map<String, Map<String, String>> standConvertMap = neoFacade.standConvert(standConvert);
         commonFacade.dataTypeSet(wordCrfDTO, standConvertMap);
 
         List<String> ruleTypeList = Arrays.asList(pushVo.getFeatureType().split(","));
@@ -57,13 +59,40 @@ public class PushFacade {
             // 获取第一个诊断
             String firstDisease = diags.get(0);
             PushDTO neoDto = map.get(firstDisease);
-            if (ruleTypeList.contains("5") && ListUtil.isNotEmpty(neoDto.getLis())) {
-                pushDTO.setLis(neoDto.getLis().subList(0, pushVo.getLength()));
-            }
 
-            if (ruleTypeList.contains("6") && ListUtil.isNotEmpty(neoDto.getPacs())) {
-                pushDTO.setPacs(neoDto.getPacs().subList(0, pushVo.getLength()));
+            if (neoDto != null) {
+                int length = pushVo.getLength();
+                // 症状
+                if (ruleTypeList.contains("1") && ListUtil.isNotEmpty(neoDto.getSymptom())) {
+                    pushDTO.setSymptom(neoDto.getSymptom().subList(0, length));
+                }
+
+                // 查体
+                if (ruleTypeList.contains("4") && ListUtil.isNotEmpty(neoDto.getVital())) {
+                    pushDTO.setVital(neoDto.getVital().subList(0, length));
+                }
+
+                // 化验
+                if (ruleTypeList.contains("5") && ListUtil.isNotEmpty(neoDto.getVital())) {
+                    pushDTO.setLis(neoDto.getLis().subList(0, length));
+                }
+
+                // 辅检
+                if (ruleTypeList.contains("6") && ListUtil.isNotEmpty(neoDto.getPacs())) {
+                    pushDTO.setPacs(neoDto.getPacs().subList(0, length));
+                }
+
+                // 诊断
+                if (ruleTypeList.contains("7") && neoDto.getDis() != null) {
+                    Map<String, List<PushBaseDTO>> disMap = neoDto.getDis();
+                    Map<String, List<PushBaseDTO>> resMap = new HashMap<>();
+                    for (String key : disMap.keySet()) {
+                        resMap.put(key, disMap.get(key).subList(0, length));
+                    }
+                    pushDTO.setDis(resMap);
+                }
             }
+
         }
         return pushDTO;
     }

+ 1 - 1
src/main/java/com/diagbot/model/ai/ModelAI.java

@@ -182,7 +182,7 @@ public class ModelAI {
      * @param string2
      * @return
      */
-    public JSONArray loadChiefPresentSimilarAI(String string1, List<String> string2, boolean directionCheck
+    public JSONArray loadSimilarAI(String string1, List<String> string2, boolean directionCheck
             , String modelName, ChiefPresentSimilarityServiceClient chiefPresentSimilarityServiceClient) {
         //存储CRF完整所需结构数据
         ChiefPresentSimilarityVo similarityVo = new ChiefPresentSimilarityVo();