Browse Source

Merge branch 'master' of http://192.168.2.236:10080/louhr/push.git

lantone 5 years ago
parent
commit
d48641b1f2
31 changed files with 58792 additions and 94 deletions
  1. 17 7
      algorithm/src/main/java/org/algorithm/core/neural/TensorflowModel.java
  2. 4 3
      algorithm/src/main/java/org/algorithm/core/neural/dataset/NNDataSet.java
  3. 6 0
      bigdata-web/pom.xml
  4. 1 1
      bigdata-web/src/main/java/org/diagbot/bigdata/work/AlgorithmCore.java
  5. 4 4
      bigdata-web/src/main/java/org/diagbot/bigdata/work/ResultDataProxy.java
  6. 199 0
      bigdata-web/src/test/java/org/diagbot/Rule2AppTest.java
  7. 187 0
      bigdata-web/src/test/java/org/diagbot/RuleTest.java
  8. 11 2
      common-push/src/main/java/org/diagbot/common/push/bean/CrisisDetail.java
  9. 10 0
      common-push/src/main/java/org/diagbot/common/push/bean/Rule.java
  10. 15 6
      common-push/src/main/java/org/diagbot/common/push/bean/SearchData.java
  11. 2 1
      common-push/src/main/java/org/diagbot/common/push/cache/ApplicationCacheUtil.java
  12. 5 3
      common-push/src/main/java/org/diagbot/common/push/cache/CacheFileManager.java
  13. 17 1
      common-push/src/main/java/org/diagbot/common/push/filter/rule/PretreatmentRule.java
  14. 2 2
      common-push/src/main/java/org/diagbot/common/push/work/ParamsDataProxy.java
  15. 33 0
      nlp-web/src/main/java/org/diagbot/nlp/controller/SimilarController.java
  16. 3 0
      nlp/src/main/java/org/diagbot/nlp/participle/cfg/Configuration.java
  17. 61 21
      nlp/src/main/java/org/diagbot/nlp/participle/cfg/DefaultConfig.java
  18. 10 0
      nlp/src/main/java/org/diagbot/nlp/rule/pretreat/PretreatmentNormal.java
  19. 22 13
      nlp/src/main/java/org/diagbot/nlp/rule/pretreat/PretreatmentOther.java
  20. 10 2
      nlp/src/main/java/org/diagbot/nlp/rule/pretreat/PretreatmentPacs.java
  21. 74 0
      nlp/src/main/java/org/diagbot/nlp/rule/pretreat/PretreatmentPast.java
  22. 7 4
      nlp/src/main/java/org/diagbot/nlp/rule/pretreat/PretreatmentVital.java
  23. 92 0
      nlp/src/main/java/org/diagbot/nlp/similar/SimilarCacheFileManager.java
  24. 44 0
      nlp/src/main/java/org/diagbot/nlp/similar/SimilarCacheUtil.java
  25. 21 0
      nlp/src/main/java/org/diagbot/nlp/similar/SimilarUtil.java
  26. 11 2
      nlp/src/main/java/org/diagbot/nlp/util/NegativeEnum.java
  27. 57738 0
      nlp/src/main/resources/bigdata_similar.dict
  28. 110 0
      nlp/src/test/java/org/diagbot/nlp/test/Similar2DBTest.java
  29. 3 0
      push-web/src/main/java/org/diagbot/push/controller/AlgorithmController.java
  30. 2 2
      push-web/src/main/resources/static/pages/algorithm/list.html
  31. 71 20
      rule/src/main/java/org/diagbot/rule/crisis/CrisisApplication.java

+ 17 - 7
algorithm/src/main/java/org/algorithm/core/neural/TensorflowModel.java

@@ -107,23 +107,33 @@ public class TensorflowModel {
                 FloatBuffer.wrap(inputValues)
         );
 
+        float[][] result = null;
+        Tensor<?> t = null;
         // 序列数据
         if (this.withSequenceInputs){
             Map<String, Tensor<Integer>> sequenceTensorMap = this.wrapSequenceInputs(sequenceValues, numExamples);
-            this.session.runner();
 
-            return this.session.runner().feed(this.X, inputTensor)
+            t = this.session.runner().feed(this.X, inputTensor)
                     .feed(this.Char_ids, sequenceTensorMap.get(this.Char_ids))
                     .feed(this.Pos_ids, sequenceTensorMap.get(this.Pos_ids))
                     .feed("keep_prob", Tensor.create(1.0f, Float.class))  // dropout保留率
-                    .fetch(this.SOFT_MAX).run().get(0)
-                    .copyTo(new float[numExamples][this.NUM_LABEL]);
+                    .fetch(this.SOFT_MAX).run().get(0);
+
+            for (Map.Entry<String, Tensor<Integer>> entry : sequenceTensorMap.entrySet()) {
+                entry.getValue().close();
+            }
+
         }else{
-            return this.session.runner().feed(this.X, inputTensor)
+            t =  this.session.runner().feed(this.X, inputTensor)
                     .feed("keep_prob", Tensor.create(1.0f, Float.class))  // dropout保留率
-                    .fetch(this.SOFT_MAX).run().get(0)
-                    .copyTo(new float[numExamples][this.NUM_LABEL]);
+                    .fetch(this.SOFT_MAX).run().get(0);
         }
+        result = t.copyTo(new float[numExamples][this.NUM_LABEL]);
+
+        t.close();
+        inputTensor.close();
+
+        return result;
     }
 
 

+ 4 - 3
algorithm/src/main/java/org/algorithm/core/neural/dataset/NNDataSet.java

@@ -27,7 +27,7 @@ public abstract class NNDataSet {
 
     // 再分词和疾病过滤相关容器
     protected final Map<String, String> RE_SPLIT_WORD_DICT = new HashMap<>();  // 在分词表
-    protected final List<String> FEATURE_NAME_STORE = new ArrayList<>();  // 特征保存
+    protected List<String> FEATURE_NAME_STORE = new ArrayList<>();  // 特征保存
     protected final Map<String, Map<String, Integer>> RELATED_DIAGNOSIS_DICT = new HashMap<>();  // 特征与疾病相关表
     private boolean doFilterDiagnosis = false;  // 是否做疾病过滤
 
@@ -352,8 +352,9 @@ public abstract class NNDataSet {
      * @param features
      */
     public void storeFeatureNames(Map<String, Map<String, String>> features) {
-        this.FEATURE_NAME_STORE.size();  // this.FEATURE_NAME_STORE.clear() 未知原因会出现数据越界异常,加了这个则没有了
-        this.FEATURE_NAME_STORE.clear();
+//        this.FEATURE_NAME_STORE.size();  // this.FEATURE_NAME_STORE.clear() 未知原因会出现数据越界异常,加了这个则没有了
+//        this.FEATURE_NAME_STORE.clear();
+        this.FEATURE_NAME_STORE = new ArrayList<>();
         this.FEATURE_NAME_STORE.addAll(features.keySet());
     }
 

+ 6 - 0
bigdata-web/pom.xml

@@ -77,6 +77,12 @@
             <version>1.2.5</version>
         </dependency>
 
+		<dependency>
+			<groupId>net.sourceforge.jexcelapi</groupId>
+			<artifactId>jxl</artifactId>
+			<version>2.6.12</version>
+		</dependency>
+
 		<dependency>
 			<groupId>mysql</groupId>
 			<artifactId>mysql-connector-java</artifactId>

+ 1 - 1
bigdata-web/src/main/java/org/diagbot/bigdata/work/AlgorithmCore.java

@@ -53,7 +53,7 @@ public class AlgorithmCore {
             switch (searchData.getAlgorithmType() == null ? 1 : searchData.getAlgorithmType()) {
                 case 1: //机器学习算法推理
                     executor = AlgorithmFactory.getInstance(classifies[i]);
-                    if (FeatureType.parse(featureTypes[i]) == FeatureType.DIAG) {
+                    if (FeatureType.parse(featureTypes[i]) == FeatureType.DIAG && !"2".equals(searchData.getSysCode())) {
                         bigDataSearchData.setLength(6);//模型推送最多6个比较合理
                     }
                     break;

+ 4 - 4
bigdata-web/src/main/java/org/diagbot/bigdata/work/ResultDataProxy.java

@@ -151,13 +151,13 @@ public class ResultDataProxy {
      * @return
      */
     public ResponseData resultSexAgeFilter(HttpServletRequest request, ResponseData responseData, SearchData searchData) {
-        if (responseData.getLabs().size() > 0) {//化验
+        if (responseData.getLabs() != null && responseData.getLabs().size() > 0) {//化验
             responseData.setLabs(sexFilter(request, responseData.getLabs(), searchData, Constants.feature_type_lis));
         }
-        if (responseData.getPacs().size() > 0) {//辅检
+        if (responseData.getPacs() != null && responseData.getPacs().size() > 0) {//辅检
             responseData.setPacs(sexFilter(request, responseData.getPacs(), searchData, Constants.feature_type_pacs));
         }
-        if (responseData.getVitals().size() > 0) {//查体
+        if (responseData.getVitals() != null && responseData.getVitals().size() > 0) {//查体
             responseData.setVitals(sexFilter(request, responseData.getVitals(), searchData, Constants.feature_type_vital));
         }
         return responseData;
@@ -180,7 +180,7 @@ public class ResultDataProxy {
                 ResultMappingFilter filter = filterMap.get(featureRate.getFeatureName());
                 if (filter != null) {
                     if (filter.getSex() != null && !StringUtils.isEmpty(searchData.getSex())
-                            && !filter.getSex().equals(searchData.getSex())) {      //性别过滤
+                            && filter.getSex().equals(searchData.getSex()) || filter.getSex().equals("3")) {      //性别过滤
                         isFirst = true;
                     } else {
                         isFirst = false;

+ 199 - 0
bigdata-web/src/test/java/org/diagbot/Rule2AppTest.java

@@ -0,0 +1,199 @@
+package org.diagbot;
+
+import jxl.Cell;
+import jxl.Sheet;
+import jxl.Workbook;
+import jxl.read.biff.BiffException;
+import jxl.write.Label;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableFont;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import org.diagbot.pub.jdbc.MysqlJdbc;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @Author: HUJING
+ * @Date: 2019/11/21 17:08
+ */
+public class Rule2AppTest {
+    public static void main(String[] args) {
+        Map<String, String> ruleId = getRuleId();
+        //        for (Map.Entry<String, Integer> ruleAndId:ruleId.entrySet()) {
+        //            System.out.println(ruleAndId.getValue() + "---" + ruleAndId.getKey());
+        //        }
+        String fileNameRead = "D:\\大数据小组\\慢病\\11.病历评级案例-20191024心内科&呼吸科.xls";
+        String fileNameWrite = "D:\\大数据小组\\慢病\\病历评级规则app列表20191125.xls";
+        readExcel(fileNameRead);
+        writeExcel(ruleId, readExcel(fileNameRead), fileNameWrite);
+    }
+
+    public static void writeExcel(Map<String, String> ruleId, List<List<String>> ruleList, String fileName) {
+        String[] title = { "编码", "是否删除", "记录创建时间", "记录修改时间", "创建人", "修改人", "指标名称", "规则类别", "提醒内容" };
+        File file = new File(fileName);
+        if (file.exists()) {
+            //如果文件存在就删除
+            file.delete();
+        }
+        try {
+            file.createNewFile();
+            WritableFont font = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.BOLD);
+            WritableCellFormat format = new WritableCellFormat(font);
+            //创建工作簿
+            WritableWorkbook workbookA = Workbook.createWorkbook(file);
+            //创建sheet
+            WritableSheet sheetA = workbookA.createSheet("sheet1", 0);
+            Label labelA = null;
+            //设置列名
+            for (int j = 0; j < title.length; j++) {
+                labelA = new Label(j, 0, title[j], format);
+                sheetA.addCell(labelA);
+            }
+            int row = 1;
+            for (int i = 0; i < ruleList.size(); i++) {
+                List<String> rule = ruleList.get(i);
+                if (rule.size() == 2 || rule.size() == 3) {
+                    String[] pacsOrder = rule.get(0).split("、");
+                    String[] rules = rule.get(1).split("、");
+                    for (int j = 0; j < pacsOrder.length; j++) {
+                        String content = "";
+                        for (int k = 0; k < rules.length; k++) {
+                            /** 原规则app样式
+                             * labelA = new Label(6, row, ruleId.get(pacsOrder[j]) + "," + ruleId.get(rules[k]));
+                             * sheetA.addCell(labelA);
+                             * labelA = new Label(8, row, rules[k] + ",不宜做" + pacsOrder[j]);
+                             * sheetA.addCell(labelA);
+                             * row++;*/
+                            String feature = ruleId.get(rules[k]) != null ? ruleId.get(rules[k]) : rules[k];
+                            if (rules[k].contains("血小板计数(PLT)")){
+                                feature = "131";
+                            } else if (rules[k].contains("氧饱和度(O2sat)")){
+                                feature = "138";
+                            } else if (rules[k].contains("经期")){
+                                feature = "70、71";
+                            } else if (rules[k].contains("妊娠")){
+                                feature = "164、165";
+                            } else if (rules[k].contains("妊娠1-3个月")){
+                                feature = "166、167";
+                            }
+
+                            String[] featureArr = feature.split("、");
+                            for (int l = 0; l < featureArr.length; l++) {
+                                if (k == rules.length - 1 && l == featureArr.length - 1) {
+                                    content += ruleId.get(pacsOrder[j]) + "," + featureArr[l];
+                                } else {
+                                    content += ruleId.get(pacsOrder[j]) + "," + featureArr[l] + "|";
+                                }
+                            }
+                        }
+                        labelA = new Label(6, row, content);
+                        sheetA.addCell(labelA);
+                        labelA = new Label(8, row, "${remind}:" + pacsOrder[j]);
+                        sheetA.addCell(labelA);
+                        row++;
+                    }
+                }
+                //                } else if (rule.size() == 3){
+                //                    String[] rules = rule.get(1).split("、");
+                //                    for (int j = 0; j < rules.length; j++) {
+                //                        labelA = new Label(6, row, ruleId.get(rule.get(0))+","+ruleId.get(rules[j]));
+                //                        sheetA.addCell(labelA);
+                //                        labelA = new Label(8, row, rule.get(2));
+                //                        sheetA.addCell(labelA);
+                //                        row++;
+                //                    }
+                //                }
+            }
+            System.out.println("成功写入文件,请前往" + fileName + "查看文件!");
+            workbookA.write();  //写入数据
+            workbookA.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.out.println("文件写入失败,报异常...");
+        }
+    }
+
+    public static List<List<String>> readExcel(String fileName) {
+        List<List<String>> ruleList = new ArrayList<>();
+        List<String> rule = null;
+        FileInputStream fis = null;
+        try {
+            fis = new FileInputStream(new File(fileName));
+            Workbook rwb = Workbook.getWorkbook(fis);
+            Sheet[] sheet = rwb.getSheets();
+            for (int i = 0; i < sheet.length; i++) {
+                Sheet rs = rwb.getSheet(i);
+                for (int j = 1; j < rs.getRows(); j++) {
+                    rule = new ArrayList<>();
+                    String content = "";
+                    Cell[] cells = rs.getRow(j);
+                    for (int k = 0; k < cells.length; k++) {
+                        if (k == 0 || k == 2 || k == 3) {
+                            content = cells[k].getContents();
+                            rule.add(content.trim());
+                        }
+                    }
+                    ruleList.add(rule);
+                }
+            }
+            fis.close();
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (BiffException e) {
+            e.printStackTrace();
+        }
+        return ruleList;
+    }
+
+    public static Map<String, String> getRuleId() {
+        Map<String, String> ruleId = new HashMap<>();
+        MysqlJdbc jdbc = new MysqlJdbc( "root", "diagbot@20180822","jdbc:mysql://192.168.2.235:3306/med-s?useUnicode=true&characterEncoding=UTF-8");
+        Connection conn = jdbc.connect();
+        PreparedStatement pstQuery = null;
+        ResultSet rs = null;
+        String sql = "SELECT id,eq_value FROM kl_rule_pub WHERE eq_value is not null";
+        try {
+            pstQuery = conn.prepareStatement(sql);
+            rs = pstQuery.executeQuery();
+            while (rs.next()) {
+                String id = String.valueOf(rs.getInt(1));
+                String eqValue = rs.getString(2).trim();
+                ruleId.put(eqValue, id);
+            }
+            ruleId.put("收缩压≥180mmHg", "74");
+            ruleId.put("舒张压≥110mmHg", "75");
+            ruleId.put("收缩压≤80mmHg", "29");
+            ruleId.put("舒张压≤50mmHg", "30");
+            ruleId.put("收缩压≥140mmHg", "129");
+            ruleId.put("舒张压≥90mmHg", "130");
+            ruleId.put("体温>39.1℃", "122");
+            ruleId.put("体温>37.3℃", "123");
+            ruleId.put("凝血酶原时间(PT)对照>5s", "132");
+            ruleId.put("活化部分凝血活酶(APTT)对照>10s", "133");
+            ruleId.put("T7至L3椎体MR增强", "648");
+            ruleId.put("体温>39.0℃", "743");
+
+            rs.close();
+            pstQuery.close();
+            conn.close();
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+        return ruleId;
+    }
+}

+ 187 - 0
bigdata-web/src/test/java/org/diagbot/RuleTest.java

@@ -0,0 +1,187 @@
+package org.diagbot;
+
+import org.diagbot.common.push.bean.Rule;
+import org.diagbot.common.push.bean.SearchData;
+import org.diagbot.common.push.filter.rule.PretreatmentRule;
+import org.diagbot.nlp.rule.module.PreResult;
+import org.diagbot.pub.jdbc.MysqlJdbc;
+import org.springframework.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by louhr on 2019/11/22.
+ */
+public class RuleTest {
+    public static void main(String[] args) {
+        RuleTest test = new RuleTest();
+        try {
+            test.validatePub();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void validatePub() throws Exception {
+        MysqlJdbc nlpJdbc = new MysqlJdbc("root", "diagbot@20180822", "jdbc:mysql://192.168.2.235:3306/med-s?useUnicode=true&characterEncoding=UTF-8");
+        List<Map<String, String>> data = nlpJdbc.query("kl_rule_pub",
+                new String[]{"id", "pub_name", "min_operator", "min_value", "min_unit",
+                        "max_operator", "max_value", "max_unit", "eq_operator", "eq_value", "eq_unit", "remind", "suffix_info"}, "");
+
+        List<Map<String, Object>> updates = new ArrayList<>();
+        List<Map<String, Object>> wheres = new ArrayList<>();
+        //数据预处理
+        PretreatmentRule pretreatmentRule = new PretreatmentRule();
+        for (Map<String, String> map : data) {
+            SearchData searchData = new SearchData();
+            searchData.setSysCode("1");
+            createSearchData(searchData, map);
+
+            Map<String, Object> line = new HashMap<>();
+            Map<String, Object> where = new HashMap<>();
+
+            pretreatmentRule.rule(searchData);
+            Map<String, List<Rule>> rules = searchData.getRules();
+            for (Map.Entry<String, List<Rule>> entry : rules.entrySet()) {
+                if (entry.getValue().size() > 0) {
+                    line.put("rule_type", "9");
+                    where.put("id", map.get("id"));
+
+                    updates.add(line);
+                    wheres.add(where);
+                    break;
+                }
+            }
+        }
+
+        nlpJdbc.update("kl_rule_pub", updates, wheres);
+    }
+
+    private void validateApp() throws Exception {
+        MysqlJdbc nlpJdbc = new MysqlJdbc("root", "diagbot@20180822", "jdbc:mysql://192.168.2.235:3306/med-s?useUnicode=true&characterEncoding=UTF-8");
+        List<Map<String, String>> data = nlpJdbc.query("kl_rule_pub",
+                new String[]{"id", "pub_name", "min_operator", "min_value", "min_unit",
+                        "max_operator", "max_value", "max_unit", "eq_operator", "eq_value", "eq_unit", "remind", "suffix_info"}, "");
+
+        Map<String, Map<String, String>> rulesMap = new HashMap<>();
+        for (Map<String, String> map : data) {
+            rulesMap.put(map.get("id"), map);
+        }
+
+        data = nlpJdbc.query("kl_rule_app", new String[]{"id", "rule_id"}, "");
+        for (Map<String, String> map : data) {
+
+        }
+
+        List<Map<String, Object>> updates = new ArrayList<>();
+        List<Map<String, Object>> wheres = new ArrayList<>();
+    }
+
+    private SearchData createSearchData(SearchData searchData, Map<String, String> map) {
+        double value = 0.0;
+        if (!StringUtils.isEmpty(map.get("eq_operator")) && "=".equals(map.get("eq_operator"))) {
+            if ("诊断--".equals(map.get("pub_name"))) {
+                searchData.setDiag(map.get("eq_value"));
+            }
+            if ("体征--".equals(map.get("pub_name"))) {
+                searchData.setVital(map.get("eq_value"));
+            }
+            if ("开单--".equals(map.get("pub_name"))) {
+                searchData.setLisOrder(map.get("eq_value"));
+                searchData.setPacsOrder(map.get("eq_value"));
+            }
+            if ("症状--".equals(map.get("pub_name"))) {
+                searchData.setSymptom(map.get("eq_value"));
+            }
+            if ("药品--".equals(map.get("pub_name"))) {
+                searchData.setPasts(map.get("eq_value"));
+            }
+            if ("既往--".equals(map.get("pub_name"))) {
+                searchData.setPasts(map.get("eq_value"));
+            }
+            if ("过敏--".equals(map.get("pub_name"))) {
+                searchData.setPasts(map.get("eq_value"));
+            }
+            if (map.get("pub_name").indexOf("其他--") > -1) {
+                searchData.setOther(map.get("pub_name") + map.get("eq_value"));
+            }
+            if (map.get("pub_name").indexOf("检查--") > -1) {
+                searchData.setPacs(map.get("pub_name") + map.get("eq_value"));
+            }
+        } else if (!StringUtils.isEmpty(map.get("min_operator")) && !StringUtils.isEmpty(map.get("max_operator"))) {
+            if (map.get("pub_name").indexOf("体征--") > -1) {
+                value = Double.valueOf(map.get("min_value")) + 0.1;
+                searchData.setVital(map.get("pub_name") + value + map.get("min_unit"));
+            }
+            if (map.get("pub_name").indexOf("其他--") > -1) {
+                value = Double.valueOf(map.get("min_value")) + 0.1;
+                searchData.setOther(map.get("pub_name") + value + map.get("min_unit"));
+            }
+            if (map.get("pub_name").indexOf("化验--") > -1) {
+                value = Double.valueOf(map.get("min_value")) + 0.1;
+                List<PreResult> list = new ArrayList<>();
+                PreResult preResult = new PreResult();
+                preResult.setUniqueName(map.get("pub_name").substring(4));
+                preResult.setValue(String.valueOf(value));
+                preResult.setUnits(map.get("min_unit"));
+                list.add(preResult);
+                searchData.setLisArr(list);
+            }
+            if (map.get("pub_name").indexOf("年龄--") > -1) {
+                int v = Integer.valueOf(map.get("min_value")) + 1;
+                searchData.setAge(v);
+            }
+        } else if (!StringUtils.isEmpty(map.get("min_operator"))) {
+            if (map.get("pub_name").indexOf("体征--") > -1) {
+                value = Double.valueOf(map.get("min_value")) - 0.1;
+                searchData.setVital(map.get("pub_name") + value + map.get("min_unit"));
+            }
+            if (map.get("pub_name").indexOf("其他--") > -1) {
+                value = Double.valueOf(map.get("min_value")) - 0.1;
+                searchData.setOther(map.get("pub_name") + value + map.get("min_unit"));
+            }
+            if (map.get("pub_name").indexOf("化验--") > -1) {
+                value = Double.valueOf(map.get("min_value")) - 0.1;
+                List<PreResult> list = new ArrayList<>();
+                PreResult preResult = new PreResult();
+                preResult.setUniqueName(map.get("pub_name").substring(4));
+                preResult.setValue(String.valueOf(value));
+                preResult.setUnits(map.get("min_unit"));
+                list.add(preResult);
+                searchData.setLisArr(list);
+            }
+            if (map.get("pub_name").indexOf("年龄--") > -1) {
+                int v = Integer.valueOf(map.get("min_value")) - 1;
+                searchData.setAge(v);
+            }
+        } else if (!StringUtils.isEmpty(map.get("max_operator"))) {
+            if (map.get("pub_name").indexOf("体征--") > -1) {
+                value = Double.valueOf(map.get("max_value")) + 0.1;
+                searchData.setVital(map.get("pub_name") + value + map.get("max_unit"));
+            }
+            if (map.get("pub_name").indexOf("其他--") > -1) {
+                value = Double.valueOf(map.get("max_value")) + 0.1;
+                searchData.setOther(map.get("pub_name") + value + map.get("max_unit"));
+            }
+            if (map.get("pub_name").indexOf("化验--") > -1) {
+                value = Double.valueOf(map.get("max_value")) + 0.1;
+                List<PreResult> list = new ArrayList<>();
+                PreResult preResult = new PreResult();
+                preResult.setUniqueName(map.get("pub_name").substring(4));
+                preResult.setValue(String.valueOf(value));
+                preResult.setUnits(map.get("max_unit"));
+                list.add(preResult);
+                searchData.setLisArr(list);
+            }
+            if (map.get("pub_name").indexOf("年龄--") > -1) {
+                int v = Integer.valueOf(map.get("max_value")) + 1;
+                searchData.setAge(v);
+            }
+        }
+
+        return searchData;
+    }
+}

+ 11 - 2
common-push/src/main/java/org/diagbot/common/push/bean/CrisisDetail.java

@@ -5,8 +5,9 @@ package org.diagbot.common.push.bean;
  */
 public class CrisisDetail {
     private String remindText;
-    private String standardText;
-    private String originText;
+    private String standardText = "";
+    private String originText = "";
+    private String typeId;
 
     public String getRemindText() {
         return remindText;
@@ -31,4 +32,12 @@ public class CrisisDetail {
     public void setOriginText(String originText) {
         this.originText = originText;
     }
+
+    public String getTypeId() {
+        return typeId;
+    }
+
+    public void setTypeId(String typeId) {
+        this.typeId = typeId;
+    }
 }

+ 10 - 0
common-push/src/main/java/org/diagbot/common/push/bean/Rule.java

@@ -34,6 +34,8 @@ public class Rule {
     private String eq_unit = "";
     //提醒信息
     private String remind = "";
+    //追加到文本尾部信息
+    private String suffixInfo = "";
     //提醒信息
     private String originText = "";
 
@@ -133,6 +135,14 @@ public class Rule {
         this.remind = remind;
     }
 
+    public String getSuffixInfo() {
+        return suffixInfo;
+    }
+
+    public void setSuffixInfo(String suffixInfo) {
+        this.suffixInfo = suffixInfo;
+    }
+
     public String getOriginText() {
         return originText;
     }

+ 15 - 6
common-push/src/main/java/org/diagbot/common/push/bean/SearchData.java

@@ -34,7 +34,7 @@ public class SearchData {
     protected String pacs = "";
     protected String diag = "";
     private String diseaseName;
-    protected String past = "";
+    protected String pasts = "";
     protected String other = "";
     //当前开单lis项目
     protected String lisOrder = "";
@@ -47,7 +47,6 @@ public class SearchData {
 
     //量表
     protected String scaleName = "";
-
     //指标结果
     protected String indications="";
     //模型
@@ -62,6 +61,8 @@ public class SearchData {
     private Map<String, List<Rule>> rules = new HashMap<>();
     //特征推送走的模型 1:机器学习 2:朴素贝叶斯
     private Integer algorithmType;
+    //规则类型
+    private String ruleType;
 
     public Integer getDisType() {
         return disType;
@@ -221,12 +222,12 @@ public class SearchData {
         this.diag = diag;
     }
 
-    public String getPast() {
-        return past;
+    public String getPasts() {
+        return pasts;
     }
 
-    public void setPast(String past) {
-        this.past = past;
+    public void setPasts(String pasts) {
+        this.pasts = pasts;
     }
 
     public String getOther() {
@@ -332,4 +333,12 @@ public class SearchData {
     public void setDiseaseName(String diseaseName) {
         this.diseaseName = diseaseName;
     }
+
+    public String getRuleType() {
+        return ruleType;
+    }
+
+    public void setRuleType(String ruleType) {
+        this.ruleType = ruleType;
+    }
 }

+ 2 - 1
common-push/src/main/java/org/diagbot/common/push/cache/ApplicationCacheUtil.java

@@ -165,7 +165,7 @@ public class ApplicationCacheUtil {
         for (String line : fileContents) {
             String[] content = line.split("\\|", -1);
             Rule rule = new Rule();
-            if (content.length == 12) {
+            if (content.length == 13) {
                 rule.setId(content[0] == null ? "" : content[0]);
                 rule.setPub_name(content[1] == null ? "" : content[1]);
                 rule.setMin_operator(content[2] == null ? "" : content[2]);
@@ -178,6 +178,7 @@ public class ApplicationCacheUtil {
                 rule.setEq_value(content[9] == null ? "" : content[9]);
                 rule.setEq_unit(content[10] == null ? "" : content[10]);
                 rule.setRemind(content[11] == null ? "" : content[11]);
+                rule.setSuffixInfo(content[12] == null ? "" : content[12]);
                 if (kl_rule_filter_map.get(rule.getPub_name()) == null) {
                     rules = new ArrayList<>();
                 } else {

+ 5 - 3
common-push/src/main/java/org/diagbot/common/push/cache/CacheFileManager.java

@@ -344,11 +344,11 @@ public class CacheFileManager {
 
             //规则过滤信息
             sql = "SELECT id, pub_name, min_operator, min_value, min_unit, max_operator, max_value, " +
-                    "max_unit, eq_operator, eq_value, eq_unit, remind FROM kl_rule_pub";
+                    "max_unit, eq_operator, eq_value, eq_unit, remind,suffix_info FROM kl_rule_pub";
             st = conn.createStatement();
             rs = st.executeQuery(sql);
             fw = new FileWriter(path + "bigdata_rule_filter.dict");
-            String r6, r7, r8, r9, r10, r11, r12;
+            String r6, r7, r8, r9, r10, r11, r12,r13;
             while (rs.next()) {
                 r1 = String.valueOf(rs.getInt(1));
                 r2 = rs.getString(2);
@@ -362,6 +362,7 @@ public class CacheFileManager {
                 r10 = rs.getString(10);
                 r11 = rs.getString(11);
                 r12 = rs.getString(12);
+                r13 = rs.getString(13);
                 r1 = StringUtils.isEmpty(r1) ? "" : r1;
                 r2 = StringUtils.isEmpty(r2) ? "" : r2;
                 r3 = StringUtils.isEmpty(r3) ? "" : r3;
@@ -374,9 +375,10 @@ public class CacheFileManager {
                 r10 = StringUtils.isEmpty(r10) ? "" : r10;
                 r11 = StringUtils.isEmpty(r11) ? "" : r11;
                 r12 = StringUtils.isEmpty(r12) ? "" : r12;
+                r13 = StringUtils.isEmpty(r13) ? "" : r13;
                 fw.write(encrypDES.encrytor(r1 + "|" + r2 + "|" + r3 + "|" + r4 + "|" + r5
                         + "|" + r6 + "|" + r7 + "|" + r8 + "|" + r9 + "|" + r10 + "|" + r11
-                        + "|" + r12));
+                        + "|" + r12 + "|" + r13));
                 fw.write("\n");
             }
             fw.close();

+ 17 - 1
common-push/src/main/java/org/diagbot/common/push/filter/rule/PretreatmentRule.java

@@ -30,6 +30,10 @@ public class PretreatmentRule {
         }
         //lis结构化信息
         if (searchData.getLisArr() != null && searchData.getLisArr().size() > 0) {
+            List<PreResult> preResults = searchData.getLisArr();
+            for (PreResult result : preResults) {
+                result.setUniqueName("化验--" + result.getUniqueName());
+            }
             searchData.setLis(add2PreResultList(searchData.getLisArr(), searchData.getLis(), "lis", searchData));
         } else if (!StringUtils.isEmpty(searchData.getLis())) {
             searchData.setLis(add2PreResultList(new PretreatmentLis(), searchData.getLis(), "lis", searchData));
@@ -38,8 +42,13 @@ public class PretreatmentRule {
         if (!StringUtils.isEmpty(searchData.getPacs())) {
             searchData.setPacs(add2PreResultList(new PretreatmentPacs(), searchData.getPacs(), "pacs", searchData));
         }
+        //既往史
+        if (!StringUtils.isEmpty(searchData.getPasts())) {
+            searchData.setPasts(add2PreResultList(new PretreatmentPast(), searchData.getPasts(), "past", searchData));
+        }
         //其他史
         if (!StringUtils.isEmpty(searchData.getOther())) {
+            add2PreResultList(new PretreatmentOther(), searchData.getSymptom(), "symptom-other", searchData);
             searchData.setOther(add2PreResultList(new PretreatmentOther(), searchData.getOther(), "other", searchData));
         }
         //开具诊断
@@ -54,6 +63,13 @@ public class PretreatmentRule {
         if (!StringUtils.isEmpty(searchData.getPacsOrder())) {
             add2PreResultList(new PretreatmentMakeList(), searchData.getPacsOrder(), "pacsOrder", searchData);
         }
+
+//        Map<String, List<Rule>> ruleMap = searchData.getRules();
+//        for (Map.Entry<String, List<Rule>> entry : ruleMap.entrySet()) {
+//            for (Rule rule : entry.getValue()) {
+//                System.out.println("id:" + rule.getId() + "; pub_name: " + rule.getPub_name());
+//            }
+//        }
     }
 
     private String add2PreResultList(Pretreatment pretreatment, String content, String ruleType, SearchData searchData) throws java.io.IOException {
@@ -87,7 +103,7 @@ public class PretreatmentRule {
                             accord_rule_map.put(ruleType, accord_rules);
                             searchData.setRules(accord_rule_map);
 
-                            content = content + (rule.getRemind() == null ? "" : rule.getRemind());
+                            content = content + (rule.getRemind() == null ? "" : rule.getSuffixInfo());
                         }
                     }
                 }

+ 2 - 2
common-push/src/main/java/org/diagbot/common/push/work/ParamsDataProxy.java

@@ -99,9 +99,9 @@ public class ParamsDataProxy {
             featuresList = fa.start(searchData.getVital(), FeatureType.FEATURE);
             paramFeatureInit(searchData, featuresList);
         }
-        if (!StringUtils.isEmpty(searchData.getPast())) {
+        if (!StringUtils.isEmpty(searchData.getPasts())) {
             //提取既往史
-            featuresList = fa.start(searchData.getPast(), FeatureType.FEATURE);
+            featuresList = fa.start(searchData.getPasts(), FeatureType.FEATURE);
             paramFeatureInit(searchData, featuresList);
         }
         if (!StringUtils.isEmpty(searchData.getOther()) || !StringUtils.isEmpty(searchData.getIndications())) {

+ 33 - 0
nlp-web/src/main/java/org/diagbot/nlp/controller/SimilarController.java

@@ -0,0 +1,33 @@
+package org.diagbot.nlp.controller;
+
+import org.diagbot.nlp.similar.SimilarCacheUtil;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @Author: HUJING
+ * @Date: 2019/10/25 10:38
+ */
+@Controller
+@RequestMapping("/similar")
+public class SimilarController {
+
+    @RequestMapping(value = "/getsimilar", method = RequestMethod.POST)
+    @ResponseBody
+    public static List<String> getSimilarList(@RequestBody String inputWord) {
+        Map<String, List<String>> similarDictMap = SimilarCacheUtil.getSimilar_dict_map();
+        if (similarDictMap.get(inputWord) != null && similarDictMap.get(inputWord).size() > 0) {
+            return similarDictMap.get(inputWord);
+        }
+        return new ArrayList<>();
+    }
+}

+ 3 - 0
nlp/src/main/java/org/diagbot/nlp/participle/cfg/Configuration.java

@@ -10,5 +10,8 @@ public interface Configuration {
 	public Segment loadMainDict(List<String> dicts);
 	public Map<String, String> loadMapDict(String path);
 	public List<String> readFileContents(String path);
+	public List<String> readDirectFileContents(String path);
+	public List<String> readTargetFileContents(String path);
 	void writeFileContents(List<String> contents, String path);
+
 }

+ 61 - 21
nlp/src/main/java/org/diagbot/nlp/participle/cfg/DefaultConfig.java

@@ -86,35 +86,28 @@ public class DefaultConfig implements Configuration {
     }
 
     public List<String> readFileContents(String path) {
-        if (!StringUtils.isEmpty(path_prefix)) path = path_prefix + path;
+        if (!StringUtils.isEmpty(path_prefix)) {
+            path = path_prefix + path;
+        }
+        return readDirectFileContents(path);
+    }
+
+    public List<String> readDirectFileContents(String path) {
         InputStream is = null;
         List<String> fileContents = new ArrayList<String>(10);
         try {
-            if (StringUtils.isEmpty(path)) path = DEFAULT_PATH;
-            is = this.getClass().getClassLoader().getResourceAsStream(path);
+            if (StringUtils.isEmpty(path)) {
+                path = DEFAULT_PATH;
+            }
+            //            is = this.getClass().getClassLoader().getResourceAsStream(path);
             File file = new File(path);
-//            File file = new File(this.getClass().getResource(path).getFile());
+            //            File file = new File(this.getClass().getResource(path).getFile());
             is = new FileInputStream(file);
             if (is == null) {
                 throw new RuntimeException(path + ".......文件未找到!!");
             }
 
-            BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512);
-
-            EncrypDES encrypDES = new EncrypDES();
-            String theWord = null;
-            int i = 0;
-            do {
-                theWord = br.readLine();
-                if (theWord != null && !"".equals(theWord.trim())) {
-                    if (i == 5) {
-                        logger.info("读取文件第六行解密前:" + theWord.trim());
-                        logger.info("读取文件第六行解密后:" + encrypDES.decryptor(theWord.trim()));
-                    }
-                    fileContents.add(encrypDES.decryptor(theWord.trim()));
-                }
-                i++;
-            } while (theWord != null);
+            addFileContents(is, fileContents);
         } catch (Exception ioe) {
             System.err.println("读取文件" + path + "出错.......................");
             ioe.printStackTrace();
@@ -124,12 +117,59 @@ public class DefaultConfig implements Configuration {
         return fileContents;
     }
 
+    public List<String> readTargetFileContents(String path) {
+        InputStream is = null;
+        List<String> fileContents = new ArrayList<String>(10);
+        try {
+            if (StringUtils.isEmpty(path)) {
+                path = DEFAULT_PATH;
+            }
+            is = this.getClass().getClassLoader().getResourceAsStream(path);
+            //            File file = new File(path);
+            //            File file = new File(this.getClass().getResource(path).getFile());
+            //            is = new FileInputStream(file);
+            if (is == null) {
+                throw new RuntimeException(path + ".......文件未找到!!");
+            }
+
+            addFileContents(is, fileContents);
+        } catch (Exception ioe) {
+            System.err.println("读取文件" + path + "出错.......................");
+            ioe.printStackTrace();
+        } finally {
+            this.close(is);
+        }
+        return fileContents;
+    }
+
+    public void addFileContents(InputStream is, List<String> fileContents) throws Exception {
+        BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512);
+
+        EncrypDES encrypDES = new EncrypDES();
+        String theWord = null;
+        int i = 0;
+        do {
+            theWord = br.readLine();
+            if (theWord != null && !"".equals(theWord.trim())) {
+                if (i == 5) {
+                    logger.info("读取文件第六行解密前:" + theWord.trim());
+                    logger.info("读取文件第六行解密后:" + encrypDES.decryptor(theWord.trim()));
+                }
+                fileContents.add(encrypDES.decryptor(theWord.trim()));
+            }
+            i++;
+        } while (theWord != null);
+    }
+
+
     public void writeFileContents(List<String> contents, String path) {
         this.writeFileContents(contents, path, "");
     }
 
     public void writeFileContents(List<String> contents, String path, String separator) {
-        if (!StringUtils.isEmpty(path_prefix)) path = path_prefix + path;
+        if (!StringUtils.isEmpty(path_prefix)) {
+            path = path_prefix + path;
+        }
         try {
             FileWriter fw = new FileWriter(path);
             for (String content : contents) {

+ 10 - 0
nlp/src/main/java/org/diagbot/nlp/rule/pretreat/PretreatmentNormal.java

@@ -24,6 +24,16 @@ public class PretreatmentNormal extends Pretreatment {
                     preResults.add(result);
                     return preResults;
                 }
+            } else if (l.getText().equals("婚姻") && i < lexemes.size() - 1) {
+                Lexeme afterLexeme = lexemes.get(i + 1);
+                if ("己婚".equals(afterLexeme.getText()) || "未婚".equals(afterLexeme.getText())) {
+                    PreResult result = new PreResult();
+                    result.setUniqueName(l.getText()+"--");
+                    result.setDetailName(l.getText()+"--");
+                    result.setValue(afterLexeme.getText());
+                    preResults.add(result);
+                    return preResults;
+                }
             }
         }
         return preResults;

+ 22 - 13
nlp/src/main/java/org/diagbot/nlp/rule/pretreat/PretreatmentOther.java

@@ -11,24 +11,22 @@ import java.util.ArrayList;
 import java.util.List;
 
 public class PretreatmentOther extends Pretreatment {
-    protected NegativeEnum[] nees_disease = new NegativeEnum[]{NegativeEnum.DISEASE};
-    protected NegativeEnum[] nees_operation = new NegativeEnum[]{NegativeEnum.OPERATION};
+    protected NegativeEnum[] nees_married = new NegativeEnum[]{NegativeEnum.MARRIED_DESC};
 
     public List<PreResult> analyze(String content) throws java.io.IOException{
-        List<PreResult> preResults = new ArrayList<>();
+        List<PreResult> preResults = super.analyzeDefault(content);
+        for (PreResult result : preResults) {
+            result.setUniqueName("其他--" + result.getUniqueName());
+        }
+
         LexemePath<Lexeme> lexemes = ParticipleUtil.participle(content);
         for (int i = 0; i < lexemes.size(); i++) {
             Lexeme l = lexemes.get(i);
             PreResult result = new PreResult();
-            if (NlpUtil.isFeature(l.getProperty(), nees_disease)) {
-                result.setUniqueName("诊断--");
-                result.setDetailName("诊断--");
-                result.setValue(NlpUtil.concept(l, NegativeEnum.DISEASE));
-                preResults.add(result);
-            } else if (NlpUtil.isFeature(l.getProperty(), nees_operation)) {
-                result.setUniqueName("手术--");
-                result.setDetailName("手术--");
-                result.setValue(NlpUtil.concept(l, NegativeEnum.OPERATION));
+            if (NlpUtil.isFeature(l.getProperty(), nees_married)) {
+                result.setUniqueName("其他--");
+                result.setDetailName("其他--");
+                result.setValue(NlpUtil.concept(l, NegativeEnum.MARRIED_DESC));
                 preResults.add(result);
             }
         }
@@ -36,10 +34,21 @@ public class PretreatmentOther extends Pretreatment {
     }
 
     public PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
-        return null;
+        return super.createDefaultPreResult(lexemes, lexeme, index);
     }
 
     public String findBodyValue(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        if (cursor > 0) cursor--;
+        int search_len = 0;
+        Lexeme leftLexeme = null;
+        while (search_len < max_back_search && cursor > -1) {
+            leftLexeme = lexemes.get(cursor);
+            if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.MARRIED_DESC})) {
+                return NlpUtil.concept(leftLexeme, NegativeEnum.MARRIED_DESC);
+            }
+            search_len++;
+            cursor--;
+        }
         return null;
     }
 }

+ 10 - 2
nlp/src/main/java/org/diagbot/nlp/rule/pretreat/PretreatmentPacs.java

@@ -24,18 +24,26 @@ public class PretreatmentPacs extends Pretreatment {
             Lexeme l = lexemes.get(i);
             if (NlpUtil.isFeature(l.getProperty(), nees_pacs_result) && i > 0) {
                 int c = i - 1;
+                boolean isFind = false;
                 while (c > -1) {
                     leftLexeme = lexemes.get(c);
                     if (NlpUtil.isFeature(leftLexeme.getProperty(), nees_pacs_name)) {
                         PreResult result = new PreResult();
                         result.setValue(NlpUtil.concept(l, NegativeEnum.PACS_RESULT));
                         result.setDetailName(NlpUtil.concept(leftLexeme, NegativeEnum.PACS_NAME));
-                        result.setUniqueName(NlpUtil.concept(leftLexeme, NegativeEnum.PACS_NAME));
+                        result.setUniqueName("检查--" + NlpUtil.concept(leftLexeme, NegativeEnum.PACS_NAME));
                         preResultList.add(result);
+                        isFind = true;
                         break;
                     }
                     c--;
                 }
+                if (!isFind) {
+                    PreResult result = new PreResult();
+                    result.setValue(NlpUtil.concept(l, NegativeEnum.PACS_RESULT));
+                    result.setUniqueName("检查--");
+                    preResultList.add(result);
+                }
             } else if (NlpUtil.isFeature(l.getProperty(), nees_time_and_unit) && i > 0) {
                 PreResult result = data2Object(lexemes, l, i, l.getProperty());
                 if (result != null) {
@@ -83,7 +91,7 @@ public class PretreatmentPacs extends Pretreatment {
         if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[] { NegativeEnum.PACS_NAME })) {
             result.setDetailName(NlpUtil.concept(leftLexeme, NegativeEnum.PACS_NAME));
         } else if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[] { NegativeEnum.PACS_NAME })) {
-            result.setUniqueName(NlpUtil.concept(leftLexeme, NegativeEnum.PACS_NAME));
+            result.setUniqueName("检查--" + NlpUtil.concept(leftLexeme, NegativeEnum.PACS_NAME));
         } else {
             return null;
         }

+ 74 - 0
nlp/src/main/java/org/diagbot/nlp/rule/pretreat/PretreatmentPast.java

@@ -0,0 +1,74 @@
+package org.diagbot.nlp.rule.pretreat;
+
+import org.diagbot.nlp.participle.ParticipleUtil;
+import org.diagbot.nlp.participle.word.Lexeme;
+import org.diagbot.nlp.participle.word.LexemePath;
+import org.diagbot.nlp.rule.module.PreResult;
+import org.diagbot.nlp.util.NegativeEnum;
+import org.diagbot.nlp.util.NlpUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PretreatmentPast extends Pretreatment {
+    protected NegativeEnum[] nees_past_desc = new NegativeEnum[]{NegativeEnum.PAST_DESC};
+    protected NegativeEnum[] nees_disease = new NegativeEnum[]{NegativeEnum.DISEASE};
+    protected NegativeEnum[] nees_operation = new NegativeEnum[]{NegativeEnum.OPERATION};
+    protected NegativeEnum[] nees_allergy = new NegativeEnum[]{NegativeEnum.ALLERGY};
+    protected NegativeEnum[] nees_med = new NegativeEnum[]{NegativeEnum.MEDICINE, NegativeEnum.MEDICINE_NAME, NegativeEnum.MEDICINE_PRD};
+
+    public List<PreResult> analyze(String content) throws java.io.IOException{
+        List<PreResult> preResults = new ArrayList<>();
+        LexemePath<Lexeme> lexemes = ParticipleUtil.participle(content);
+        for (int i = 0; i < lexemes.size(); i++) {
+            Lexeme l = lexemes.get(i);
+            PreResult result = new PreResult();
+            if (NlpUtil.isFeature(l.getProperty(), nees_disease)) {
+                result.setUniqueName("诊断--");
+                result.setDetailName("诊断--");
+                result.setValue(NlpUtil.concept(l, NegativeEnum.DISEASE));
+                preResults.add(result);
+            } else if (NlpUtil.isFeature(l.getProperty(), nees_past_desc)) {
+                result.setUniqueName("既往--");
+                result.setDetailName("既往--");
+                result.setValue(NlpUtil.concept(l, NegativeEnum.PAST_DESC));
+                preResults.add(result);
+            } else if (NlpUtil.isFeature(l.getProperty(), nees_operation)) {
+                result.setUniqueName("手术--");
+                result.setDetailName("手术--");
+                result.setValue(NlpUtil.concept(l, NegativeEnum.OPERATION));
+                preResults.add(result);
+            } else if (NlpUtil.isFeature(l.getProperty(), nees_med)) {
+                result.setUniqueName("药品--");
+                result.setDetailName("药品--");
+                result.setValue(NlpUtil.concept(l, NegativeEnum.MEDICINE));
+                preResults.add(result);
+            }
+            if (l.getText().indexOf("过敏") > -1) {
+                int max_find_step = 10;
+                int position = i - 1;
+                Lexeme leftLexeme;
+                while (i - position < max_find_step && position > -1) {
+                    leftLexeme = lexemes.get(position);
+                    //遇上过敏史信息
+                    if (NlpUtil.isFeature(leftLexeme.getProperty(), nees_allergy)) {
+                        result.setUniqueName("过敏--");
+                        result.setDetailName("过敏--");
+                        result.setValue(NlpUtil.concept(leftLexeme, NegativeEnum.ALLERGY) + "过敏");
+                        preResults.add(result);
+                    }
+                    position--;
+                }
+            }
+        }
+        return preResults;
+    }
+
+    public PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        return null;
+    }
+
+    public String findBodyValue(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        return null;
+    }
+}

+ 7 - 4
nlp/src/main/java/org/diagbot/nlp/rule/pretreat/PretreatmentVital.java

@@ -15,19 +15,22 @@ public class PretreatmentVital extends Pretreatment {
 
     public List<PreResult> analyze(String content) throws java.io.IOException{
         List<PreResult> preResults = super.analyzeDefault(content);
+        for (PreResult result : preResults) {
+            result.setUniqueName("体征--" + result.getUniqueName());
+        }
         LexemePath<Lexeme> lexemes = ParticipleUtil.participle(content);
         for (int i = 0; i < lexemes.size(); i++) {
             Lexeme l = lexemes.get(i);
             if (NlpUtil.isFeature(l.getProperty(), nees_vital_result)) {
                 PreResult result = new PreResult();
-                result.setUniqueName("体征结果--");
-                result.setDetailName("体征结果--");
+                result.setUniqueName("体征--");
+                result.setDetailName("体征--");
                 result.setValue(NlpUtil.concept(l, NegativeEnum.VITAL_RESULT));
                 preResults.add(result);
             }else if (NlpUtil.isFeature(l.getProperty(), nees_vital_index)) {
                 PreResult result = new PreResult();
-                result.setUniqueName("体征结果--");
-                result.setDetailName("体征结果--");
+                result.setUniqueName("体征--");
+                result.setDetailName("体征--");
                 result.setValue(NlpUtil.concept(l, NegativeEnum.VITAL_INDEX));
                 preResults.add(result);
             }

+ 92 - 0
nlp/src/main/java/org/diagbot/nlp/similar/SimilarCacheFileManager.java

@@ -0,0 +1,92 @@
+package org.diagbot.nlp.similar;
+
+import org.diagbot.pub.jdbc.MysqlJdbc;
+import org.diagbot.pub.utils.PropertiesUtil;
+import org.diagbot.pub.utils.security.EncrypDES;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * @Description:
+ * @Author: HUJING
+ * @Date: 2019/10/16 13:46
+ */
+public class SimilarCacheFileManager {
+    private String user = "root";
+    private String password = "diagbot@20180822";
+    private String url = "jdbc:mysql://192.168.2.235:3306/med-s?useUnicode=true&characterEncoding=UTF-8";
+
+    private String path = "";
+
+    public static void main(String[] args) {
+        SimilarCacheFileManager similarCacheFileManager = new SimilarCacheFileManager();
+        String resourcePath = similarCacheFileManager.getResourcePath();
+//        PropertiesUtil propertiesUtil = new PropertiesUtil("nlp.properties");
+//        String p = propertiesUtil.getProperty("cache.file.dir");
+        File file = new File(resourcePath);
+        if (!file.exists()) {
+            file.mkdirs();
+        }
+        //相似度知识库
+        similarCacheFileManager.createSimilarCacheFile(resourcePath);
+    }
+
+    public String getResourcePath(){
+        return this.getClass().getResource("/").getPath();
+    }
+
+    public SimilarCacheFileManager() {
+//        PropertiesUtil propertiesUtil = new PropertiesUtil("nlp.properties");
+//        String p = propertiesUtil.getProperty("cache.file.dir");
+
+        String resourcePath = getResourcePath();
+        File file = new File(resourcePath);
+        if (!file.exists()) {
+            file.mkdirs();
+        }
+        path = resourcePath;
+    }
+
+    public void createCacheFile() {
+        createSimilarCacheFile(path);
+    }
+
+    public void createSimilarCacheFile(String path) {
+        MysqlJdbc nlpJdbc = new MysqlJdbc(user, password, url);
+        Connection conn = nlpJdbc.connect();
+        Statement st = null;
+        ResultSet rs = null;
+        try {
+            EncrypDES encrypDES = new EncrypDES();
+            //疾病科室
+            String sql = "SELECT similar_1,similar_2 FROM doc_similar";
+            st = conn.createStatement();
+            rs = st.executeQuery(sql);
+            FileWriter fw = new FileWriter(path + "bigdata_similar.dict");
+
+            String r1, r2;
+            while (rs.next()) {
+                r1 = rs.getString(1).trim();
+                r2 = rs.getString(2).trim();
+
+                fw.write(encrypDES.encrytor(r1 + "|" + r2));
+                fw.write("\n");
+            }
+            fw.close();
+        } catch (IOException ioe) {
+            ioe.printStackTrace();
+        } catch (SQLException sqle) {
+            sqle.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            nlpJdbc.close(rs, st, conn);
+        }
+    }
+}

+ 44 - 0
nlp/src/main/java/org/diagbot/nlp/similar/SimilarCacheUtil.java

@@ -0,0 +1,44 @@
+package org.diagbot.nlp.similar;
+
+import org.diagbot.nlp.participle.cfg.Configuration;
+import org.diagbot.nlp.participle.cfg.DefaultConfig;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @Author: HUJING
+ * @Date: 2019/10/16 15:30
+ */
+public class SimilarCacheUtil {
+    //相似度知识库
+    public static Map<String, List<String>> similar_dict_map = null;
+
+    public static Map<String, List<String>> getSimilar_dict_map() {
+        if (similar_dict_map == null) {
+            createSimilar_dict_map();
+        }
+        return similar_dict_map;
+    }
+
+    public static Map<String, List<String>> createSimilar_dict_map() {
+        similar_dict_map = new HashMap<>();
+        List<String> similarList = null;
+        Configuration configuration = new DefaultConfig();
+        List<String> fileContents = configuration.readTargetFileContents("bigdata_similar.dict");
+        for (String line:fileContents) {
+            String[] similarPair = line.split("\\|", -1);
+            if (similar_dict_map.get(similarPair[0]) == null){
+                similarList = new ArrayList<>();
+                similarList.add(similarPair[1]);
+                similar_dict_map.put(similarPair[0],similarList);
+            } else {
+                similar_dict_map.get(similarPair[0]).add(similarPair[1]);
+            }
+        }
+        return similar_dict_map;
+    }
+}

+ 21 - 0
nlp/src/main/java/org/diagbot/nlp/similar/SimilarUtil.java

@@ -0,0 +1,21 @@
+package org.diagbot.nlp.similar;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @Author: HUJING
+ * @Date: 2019/10/16 15:59
+ */
+public class SimilarUtil {
+
+    public static List<String> getSimilarList(String inputWord) {
+        Map<String, List<String>> similarDictMap = SimilarCacheUtil.getSimilar_dict_map();
+        if (similarDictMap.get(inputWord) != null && similarDictMap.get(inputWord).size() > 0){
+            return similarDictMap.get(inputWord);
+        }
+        return new ArrayList<>();
+    }
+}

+ 11 - 2
nlp/src/main/java/org/diagbot/nlp/util/NegativeEnum.java

@@ -12,8 +12,8 @@ public enum NegativeEnum {
     SYMPTOM_PERFORMANCE("26"), NUMBER_QUANTIFIER("27"), DIGITS("28"),
     OTHER("44"),
     VITAL_INDEX("33"), VITAL_INDEX_VALUE("34"), VITAL_RESULT("35"),
-    ADDRESS("36"), PERSON("38"), PERSON_FEATURE_DESC("39"), PUB_NAME("46"), MEDICINE_NAME("53"),MEDICINE_PRD("54"),
-    RETURN_VISIT("68"), DIAG_STAND("70");
+    ADDRESS("36"), PERSON("38"), PERSON_FEATURE_DESC("39"), PUB_NAME("46"), MEDICINE_NAME("53"),MEDICINE_PRD("54"),PAST_DESC("55"),ALLERGY("65"),
+    MARRIED_DESC("62"), RETURN_VISIT("68"), DIAG_STAND("70");
     private String value;
 
     NegativeEnum(String value) {
@@ -156,6 +156,15 @@ public enum NegativeEnum {
             case "54":
                 negativeEnum = NegativeEnum.MEDICINE_PRD;
                 break;
+            case "55":
+                negativeEnum = NegativeEnum.PAST_DESC;
+                break;
+            case "62":
+                negativeEnum = NegativeEnum.MARRIED_DESC;
+                break;
+            case "65":
+                negativeEnum = NegativeEnum.ALLERGY;
+                break;
             case "68":
                 negativeEnum = NegativeEnum.RETURN_VISIT;
                 break;

File diff suppressed because it is too large
+ 57738 - 0
nlp/src/main/resources/bigdata_similar.dict


+ 110 - 0
nlp/src/test/java/org/diagbot/nlp/test/Similar2DBTest.java

@@ -0,0 +1,110 @@
+package org.diagbot.nlp.test;
+
+import org.diagbot.nlp.similar.SimilarUtil;
+import org.diagbot.pub.jdbc.MysqlJdbc;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @Description:
+ * @Author: HUJING
+ * @Date: 2019/10/16 10:11
+ */
+public class Similar2DBTest {
+    private String user = "root";
+    private String password = "diagbot@20180822";
+    private String url = "jdbc:mysql://192.168.2.235:3306/med-s?useUnicode=true&characterEncoding=UTF-8";
+
+    public static void main(String[] args) {
+//        String fileName = "D:/大数据小组/相似度知识库.txt";
+//        Similar2DBTest similar2DBTest = new Similar2DBTest();
+//        Map<String, Set<String>> similarFile = similar2DBTest.readSimilarFile(fileName);
+//        similar2DBTest.write2DB(similarFile);
+        List<String> similarList = SimilarUtil.getSimilarList("表情淡漠");
+        System.out.println(similarList);
+        similarList = SimilarUtil.getSimilarList("右侧乳房");
+        System.out.println(similarList);
+//        SimilarCacheFileManager similarCacheFileManager = new SimilarCacheFileManager();
+//        String resourcePath = similarCacheFileManager.getResourcePath();
+//        System.out.println(resourcePath);
+
+    }
+
+    public Map<String, Set<String>> readSimilarFile(String fileName) {
+        BufferedReader reader = null;
+        Map<String, Set<String>> similarMap = new HashMap<>();
+        Set<String> similarSet = null;
+        try {
+            reader = new BufferedReader(new FileReader(new File(fileName)));
+            String line = "";
+            while ((line = reader.readLine()) != null) {
+                line = line.replaceAll("\'|]|\\[", "");
+                String[] words = line.split(",");
+                if (similarMap.get(words[0]) == null) {
+                    similarSet = new HashSet<>();
+                    similarSet.add(words[1]);
+                    similarMap.put(words[0], similarSet);
+                } else {
+                    similarMap.get(words[0]).add(words[1]);
+                }
+                //                System.out.println(line);
+            }
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                reader.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return similarMap;
+    }
+
+    public void write2DB(Map<String, Set<String>> similarMap) {
+        MysqlJdbc jdbc = new MysqlJdbc(user, password, url);
+        Connection conn = jdbc.connect();
+        PreparedStatement pst = null;
+        String sql = "INSERT INTO doc_similar(similar_1,similar_2) VALUES(?,?)";
+        try {
+            pst = conn.prepareStatement(sql);
+
+            String similar1 = "";
+            int i = 1;
+            for (Map.Entry<String, Set<String>> similarFileMap : similarMap.entrySet()) {
+                //            System.out.println(similarFileMap.getKey());
+                similar1 = similarFileMap.getKey();
+                pst.setString(1, similar1);
+                for (String similar2 : similarFileMap.getValue()) {
+                    pst.setString(2, similar2);
+                    System.out.println(i++);
+                    pst.addBatch();
+                    pst.executeBatch();
+                }
+            }
+        } catch (SQLException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                pst.close();
+                conn.close();
+            } catch (SQLException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}

+ 3 - 0
push-web/src/main/java/org/diagbot/push/controller/AlgorithmController.java

@@ -153,6 +153,9 @@ public class AlgorithmController extends BaseController {
 //        searchData.setLength(6);    //模型推送最多6个比较合理
         AlgorithmCore core = new AlgorithmCore();
         ResponseData bigDataResponseData = core.algorithm(request, searchData, responseData);
+        bigDataResponseData.setVitals(new ArrayList<>());
+        bigDataResponseData.setLabs(new ArrayList<>());
+        bigDataResponseData.setPacs(new ArrayList<>());
 
         GraphCalculate graphCalculate = new GraphCalculate();
         ResponseData graphResponseData = graphCalculate.calculate(request, searchData);

+ 2 - 2
push-web/src/main/resources/static/pages/algorithm/list.html

@@ -400,13 +400,13 @@
             $('#diag_list').html("");
             $('#before_combine_diag_list').html("");
             startDiag('/algorithm/page_neural', '#symptom_list', '1', resourceType, '111', '1');
-            startDiag('/algorithm/page_neural', '#vital_list', '3,2,7', resourceType, '131', '3');
+            startDiag('/algorithm/page_neural', '#vital_list', '3,2,7,42', resourceType, '131', '3');
             startDiag('/algorithm/page_neural', '#lis_list', '4,2,7', resourceType, '141', '4');
             startDiag('/algorithm/page_neural', '#pacs_list', '5,2,7', resourceType, '151', '5');
 
         } else {
             startDiag('/algorithm/page_neural', '#symptom_list', '1', resourceType, '11', '1');
-            startDiag('/algorithm/page_neural', '#vital_list', '3,2,7', resourceType, '31', '3');
+            startDiag('/algorithm/page_neural', '#vital_list', '3,2,7,42', resourceType, '31', '3');
             startDiag('/algorithm/page_neural', '#lis_list', '4,2,7', resourceType, '41', '4');
             startDiag('/algorithm/page_neural', '#pacs_list', '5,2,7', resourceType, '51', '5');
 

+ 71 - 20
rule/src/main/java/org/diagbot/rule/crisis/CrisisApplication.java

@@ -8,7 +8,9 @@ import org.diagbot.common.push.cache.ApplicationCacheUtil;
 import org.springframework.util.StringUtils;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -20,7 +22,9 @@ public class CrisisApplication {
     private String key = "crisis";
 
     public Map<String, List<CrisisDetail>> crisisContent(SearchData searchData) {
+        searchData.setRuleType("1,2");
         Map<String, List<Rule>> rules = searchData.getRules();
+        List<String> ruleTypeIdList = new ArrayList<>();
         if (rules == null) {
             return new HashMap<String, List<CrisisDetail>>();
         }
@@ -28,36 +32,73 @@ public class CrisisApplication {
 
         Map<String, List<CrisisDetail>> crisisMap = new HashMap<>();
         List<CrisisDetail> crisisList = null;
+        if (!StringUtils.isEmpty(searchData.getRuleType())) {
+            ruleTypeIdList = Arrays.asList(searchData.getRuleType().split(","));
+        }
         for (Map.Entry<String, RuleApp> app : ruleApps.entrySet()) {
-            if (StringUtils.isEmpty(app.getValue().getRuleIds())) {
+            if (StringUtils.isEmpty(app.getValue().getRuleIds()) || StringUtils.isEmpty(app.getValue().getTypeId())) {
+                continue;
+            }
+            if (!ruleTypeIdList.contains(app.getValue().getTypeId())) {
                 continue;
             }
-            String[] ruleIds = app.getValue().getRuleIds().split(",");
-            String standardText = "", originText = "";
-            boolean allRuleIdsSuit = true;
-            for (String ruleId : ruleIds) {
-                boolean isFindRule = false;
-                for (Map.Entry<String, List<Rule>> suitRules : rules.entrySet()) {
-                    for (Rule suitRule : suitRules.getValue()) {
-                        if (ruleId.equals(suitRule.getId())) {
-                            isFindRule = true;
-                            standardText += suitRule.getPub_name() + ";";
-                            originText += suitRule.getOriginText() + ";";
-                            break;
+            String appRemindVar = "";
+            String appOriginText = "";
+            boolean hasAppSuit = false;
+            String[] fieldRuleIds = app.getValue().getRuleIds().split("\\^");
+            for (String fieldRuleId : fieldRuleIds) {
+                String[] ruleIds = fieldRuleId.split(",");
+                String standardText = "", originText = "", remind = "";;
+                boolean allRuleIdsSuit = true;
+                for (String ruleId : ruleIds) {
+                    boolean isFindRule = false;
+                    for (Map.Entry<String, List<Rule>> suitRules : rules.entrySet()) {
+                        for (Rule suitRule : suitRules.getValue()) {
+                            if (ruleId.equals(suitRule.getId())) {
+                                isFindRule = true;
+                                standardText += suitRule.getPub_name() + ";";
+                                if (StringUtils.isEmpty(remind)) {
+                                    remind = suitRule.getRemind();
+                                } else if (!StringUtils.isEmpty(remind) && !StringUtils.isEmpty(suitRule.getRemind())) {
+                                    remind = remind + "," + suitRule.getRemind();
+                                }
+
+                                if (StringUtils.isEmpty(originText)) {
+                                    originText = suitRule.getOriginText();
+                                } else if (!StringUtils.isEmpty(originText) && !StringUtils.isEmpty(suitRule.getOriginText())) {
+                                    originText = originText + ";" + suitRule.getOriginText();
+                                }
+                                break;
+                            }
                         }
                     }
+                    if (!isFindRule) {
+                        allRuleIdsSuit = false;
+                        break;
+                    }
                 }
-                if (!isFindRule) {
-                    allRuleIdsSuit = false;
-                    break;
+                if (allRuleIdsSuit) {
+                    if (StringUtils.isEmpty(appRemindVar)) {
+                        appRemindVar = remind;
+                    } else {
+                        appRemindVar = appRemindVar + "," + remind;
+                    }
+                    if (StringUtils.isEmpty(appOriginText)) {
+                        appOriginText = originText;
+                    } else {
+                        appOriginText = appOriginText + "," + originText;
+                    }
+
+                    hasAppSuit = true;
                 }
             }
             //所有规则都满足
-            if (allRuleIdsSuit) {
+            if (hasAppSuit) {
                 CrisisDetail crisisDetail = new CrisisDetail();
-                crisisDetail.setOriginText(originText);
-                crisisDetail.setStandardText(standardText);
-                crisisDetail.setRemindText(app.getValue().getRemind());
+                crisisDetail.setOriginText(appOriginText);
+//                crisisDetail.setStandardText(standardText);
+                crisisDetail.setRemindText(app.getValue().getRemind().replace("${remind}", appRemindVar));
+                crisisDetail.setTypeId(app.getValue().getTypeId());
 
                 crisisList = crisisMap.get(key);
                 if (crisisList == null) {
@@ -70,6 +111,7 @@ public class CrisisApplication {
                     }
                 }
                 if (!isHave) {
+                    System.out.println("remind_text:" + crisisDetail.getRemindText());
                     crisisList.add(crisisDetail);
                 }
                 crisisMap.put(key, crisisList);
@@ -78,6 +120,15 @@ public class CrisisApplication {
         return crisisMap;
     }
 
+    private List<String> getAllRuleId(Map<String, RuleApp> ruleApps) {
+        Set<String> typeIdSet = new HashSet<>();
+        for (Map.Entry<String, RuleApp> ruleAppEntry : ruleApps.entrySet()) {
+            typeIdSet.add(ruleAppEntry.getValue().getTypeId());
+        }
+        List<String> allTypeIdList = new ArrayList<>(typeIdSet);
+        return allTypeIdList;
+    }
+
     private String mergeStandardText(Rule rule) {
         //标准值最优先匹配
         StringBuffer sb = new StringBuffer();