Explorar o código

过滤规则重写

louhr %!s(int64=5) %!d(string=hai) anos
pai
achega
be80dcb68f

+ 11 - 0
bigdata-web/src/main/java/org/diagbot/bigdata/common/ApplicationCacheUtil.java

@@ -33,6 +33,7 @@ public class ApplicationCacheUtil {
     public static Map<String, List<Map<String, String>>> kl_result_mapping_standword_map = null;
     // 规则
     public static Map<String, List<Rule>> rule_filter_map = null;
+    public static Map<String, List<Rule>> kl_rule_filter_map = null;
 
 
     public static Map<String, Map<String, String>> getStandard_info_synonym_map() {
@@ -255,6 +256,16 @@ public class ApplicationCacheUtil {
         }
     }
 
+    public static void create_kl_rule_filter_map() {
+        kl_rule_filter_map = new HashMap<>();
+
+        Configuration configuration = new DefaultConfig();
+        List<String> fileContents = configuration.readFileContents("bigdata_rule_filter.dict");
+        for (String line:fileContents) {
+            String[] content = line.split("\\|");
+        }
+    }
+
     public static void setProterty(Lexeme lexeme) {
         for (String featureType : lexeme.getProperty().split(",")) {
             switch (featureType) {

+ 35 - 0
common-push/src/main/java/org/diagbot/common/push/cache/CacheFileManager.java

@@ -5,6 +5,7 @@ import org.diagbot.pub.utils.PropertiesUtil;
 import org.diagbot.pub.utils.security.EncrypDES;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.util.StringUtils;
 
 import java.io.File;
 import java.io.FileWriter;
@@ -351,6 +352,40 @@ public class CacheFileManager {
                 fw.write("\n");
             }
             fw.close();
+
+            //规则过滤信息
+            sql = "SELECT idx_name, set_name, set_status, min_value, max_value, standard_value, " +
+                    " , unit, concept_text, crisis_status, remind FROM kl_rule_new ";
+            st = conn.createStatement();
+            rs = st.executeQuery(sql);
+            fw = new FileWriter(path + "bigdata_rule_filter.dict");
+            String r10;
+            while (rs.next()) {
+                r1 = rs.getString(1);
+                r2 = rs.getString(2);
+                r3 = rs.getString(3);
+                r4 = rs.getString(4);
+                r5 = rs.getString(5);
+                r6 = rs.getString(6);
+                r7 = rs.getString(7);
+                r8 = rs.getString(8);
+                r9 = rs.getString(9);
+                r10 = rs.getString(10);
+                r1 = StringUtils.isEmpty(r1)?"":r1;
+                r2 = StringUtils.isEmpty(r1)?"":r2;
+                r3 = StringUtils.isEmpty(r1)?"":r3;
+                r4 = StringUtils.isEmpty(r1)?"":r4;
+                r5 = StringUtils.isEmpty(r1)?"":r5;
+                r6 = StringUtils.isEmpty(r1)?"":r6;
+                r7 = StringUtils.isEmpty(r1)?"":r7;
+                r8 = StringUtils.isEmpty(r1)?"":r8;
+                r9 = StringUtils.isEmpty(r1)?"":r9;
+                r10 = StringUtils.isEmpty(r1)?"":r10;
+                fw.write(encrypDES.encrytor(r1+ "|" + r2 + "|" + r3 + "|" + r4 + "|" + r5
+                        + "|" + r6 + "|" + r7 + "|" + r8 + "|" + r9 + "|" + r10));
+                fw.write("\n");
+            }
+            fw.close();
         } catch (IOException ioe) {
             ioe.printStackTrace();
         } catch (SQLException sqle) {

+ 79 - 0
common-push/src/main/java/org/diagbot/common/push/filter/PreResult.java

@@ -0,0 +1,79 @@
+package org.diagbot.common.push.filter;
+
+/**
+ * Created by louhr on 2019/8/31.
+ */
+public class PreResult {
+    private String detailName;
+    private String uniqueName;
+    private Double maxValue;
+    private Double minValue;
+    private String name;
+    private String otherValue;
+    private String units;
+    private Double value;
+
+    public String getDetailName() {
+        return detailName;
+    }
+
+    public void setDetailName(String detailName) {
+        this.detailName = detailName;
+    }
+
+    public String getUniqueName() {
+        return uniqueName;
+    }
+
+    public void setUniqueName(String uniqueName) {
+        this.uniqueName = uniqueName;
+    }
+
+    public Double getMaxValue() {
+        return maxValue;
+    }
+
+    public void setMaxValue(Double maxValue) {
+        this.maxValue = maxValue;
+    }
+
+    public Double getMinValue() {
+        return minValue;
+    }
+
+    public void setMinValue(Double minValue) {
+        this.minValue = minValue;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getOtherValue() {
+        return otherValue;
+    }
+
+    public void setOtherValue(String otherValue) {
+        this.otherValue = otherValue;
+    }
+
+    public String getUnits() {
+        return units;
+    }
+
+    public void setUnits(String units) {
+        this.units = units;
+    }
+
+    public Double getValue() {
+        return value;
+    }
+
+    public void setValue(Double value) {
+        this.value = value;
+    }
+}

+ 45 - 0
common-push/src/main/java/org/diagbot/common/push/filter/PretreatmentFilter.java

@@ -0,0 +1,45 @@
+package org.diagbot.common.push.filter;
+
+
+import org.diagbot.common.push.filter.pretreat.Pretreatment;
+import org.diagbot.common.push.filter.pretreat.PretreatmentSymptom;
+import org.diagbot.common.push.filter.pretreat.PretreatmentVital;
+import org.diagbot.common.work.SearchData;
+import org.springframework.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PretreatmentFilter {
+    public void crisisFilter(SearchData searchData) throws java.io.IOException {
+        //将数值类型内容全部转换为标准术语  依据kl_rule提供规则
+
+        List<PreResult> allPreResultList = new ArrayList<>();
+        //症状数据
+        if (!StringUtils.isEmpty(searchData.getSymptom())) {
+            searchData.setSymptom(add2PreResultList(new PretreatmentSymptom(), searchData.getSymptom(), allPreResultList));
+        }
+        //体征数据
+        if (!StringUtils.isEmpty(searchData.getVital())) {
+            searchData.setVital(add2PreResultList(new PretreatmentVital(), searchData.getVital(), allPreResultList));
+        }
+        //lis文本非结构化数据
+        if (!StringUtils.isEmpty(searchData.getLis())) {
+            searchData.setLis(add2PreResultList(new PretreatmentVital(), searchData.getLis(), allPreResultList));
+        }
+        //pacs数据
+        if (!StringUtils.isEmpty(searchData.getPacs())) {
+            searchData.setPacs(add2PreResultList(new PretreatmentVital(), searchData.getPacs(), allPreResultList));
+        }
+    }
+
+    private String add2PreResultList(Pretreatment pretreatment, String content, List<PreResult> allPreResultList) throws java.io.IOException {
+        List<PreResult> preResultList = pretreatment.analyze(content);
+        if (preResultList != null) {
+            allPreResultList.addAll(preResultList);
+
+
+        }
+        return content;
+    }
+}

+ 88 - 0
common-push/src/main/java/org/diagbot/common/push/filter/pretreat/Pretreatment.java

@@ -0,0 +1,88 @@
+package org.diagbot.common.push.filter.pretreat;
+
+import org.diagbot.common.push.filter.PreResult;
+import org.diagbot.nlp.participle.ParticipleUtil;
+import org.diagbot.nlp.participle.word.Lexeme;
+import org.diagbot.nlp.participle.word.LexemePath;
+import org.diagbot.nlp.util.NegativeEnum;
+import org.diagbot.nlp.util.NlpUtil;
+import org.springframework.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by louhr on 2019/8/31.
+ */
+public abstract class Pretreatment {
+    protected NegativeEnum[] nees_time_and_unit = new NegativeEnum[]{NegativeEnum.EVENT_TIME, NegativeEnum.UNIT};
+
+    protected int cursor = 0;
+
+    public abstract List<PreResult> analyze(String content) throws java.io.IOException;
+
+    abstract PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index);
+
+    protected List<PreResult> analyzeDefault(String content) throws java.io.IOException{
+        LexemePath<Lexeme> lexemes = ParticipleUtil.participle(content);
+
+        List<PreResult> preResultList = new ArrayList<>();
+        for (int i = 0; i < lexemes.size(); i++) {
+            Lexeme l = lexemes.get(i);
+            if (NlpUtil.isFeature(l.getProperty(), nees_time_and_unit)) {
+                PreResult result = data2Object(lexemes, l, i, l.getProperty());
+                if (result != null) {
+                    preResultList.add(result);
+                }
+            }
+        }
+        return preResultList;
+    }
+
+    protected PreResult data2Object(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index, String property) {
+        if (index < 2) {
+            return null;
+        }
+        return createPreResult(lexemes, lexeme, index);
+    }
+
+    public PreResult createDefaultPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        double value = findNumberValue(lexemes, lexeme, index);
+        if (value == -1) return null;
+        //继续往前找本体
+        String text = findBodyValue(lexemes, lexeme, index);
+        if (StringUtils.isEmpty(text)) {
+            return null;
+        }
+        PreResult result = new PreResult();
+        result.setValue(value);
+        result.setUnits(lexeme.getText());
+        result.setDetailName(text);
+        return result;
+    }
+
+    protected double findNumberValue(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        if (index < 1) return -1;
+        cursor = index - 1;
+        Lexeme leftLexeme = lexemes.get(cursor);
+        if ("×".equals(leftLexeme.getText())) {
+            if  (cursor <= 0) return -1;
+            cursor--;
+            leftLexeme = lexemes.get(cursor);
+        }
+        if (NlpUtil.isNumberString(leftLexeme)) {
+            return NlpUtil.numberText2value(leftLexeme);
+        }
+        return -1;
+    }
+
+    protected String findBodyValue(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        if (cursor > 0) cursor--;
+        Lexeme leftLexeme = lexemes.get(cursor);
+        if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.VITAL_INDEX,
+                NegativeEnum.VITAL_INDEX_VALUE, NegativeEnum.VITAL_RESULT, NegativeEnum.SYMPTOM})) {
+            return leftLexeme.getText();
+        }
+        return null;
+    }
+}

+ 41 - 0
common-push/src/main/java/org/diagbot/common/push/filter/pretreat/PretreatmentLis.java

@@ -0,0 +1,41 @@
+package org.diagbot.common.push.filter.pretreat;
+
+import org.diagbot.common.push.filter.PreResult;
+import org.diagbot.nlp.participle.word.Lexeme;
+import org.diagbot.nlp.participle.word.LexemePath;
+import org.diagbot.nlp.util.NegativeEnum;
+import org.diagbot.nlp.util.NlpUtil;
+import org.springframework.util.StringUtils;
+
+import java.util.List;
+
+public class PretreatmentLis extends Pretreatment {
+    public List<PreResult> analyze(String content) throws java.io.IOException{
+        return super.analyzeDefault(content);
+    }
+
+    public PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        PreResult result = new PreResult();
+        double value = findNumberValue(lexemes, lexeme, index);
+        if (value == -1) return null;
+        //继续往前找化验明细项
+        if (cursor > 0) cursor--;
+        Lexeme leftLexeme = lexemes.get(cursor);
+        if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.LIS_NAME})) {
+            result.setDetailName(leftLexeme.getText());
+        } else {
+            return null;
+        }
+        //查找化验套餐
+        int position = cursor - 1;
+        while (position > -1) {
+            leftLexeme = lexemes.get(position);
+            if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.LIS_TYPE})) {
+                result.setName(leftLexeme.getText());
+                break;
+            }
+            position--;
+        }
+        return result;
+    }
+}

+ 17 - 0
common-push/src/main/java/org/diagbot/common/push/filter/pretreat/PretreatmentSymptom.java

@@ -0,0 +1,17 @@
+package org.diagbot.common.push.filter.pretreat;
+
+import org.diagbot.common.push.filter.PreResult;
+import org.diagbot.nlp.participle.word.Lexeme;
+import org.diagbot.nlp.participle.word.LexemePath;
+
+import java.util.List;
+
+public class PretreatmentSymptom extends Pretreatment {
+    public List<PreResult> analyze(String content) throws java.io.IOException{
+        return super.analyzeDefault(content);
+    }
+
+    public PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        return super.createDefaultPreResult(lexemes, lexeme, index);
+    }
+}

+ 17 - 0
common-push/src/main/java/org/diagbot/common/push/filter/pretreat/PretreatmentVital.java

@@ -0,0 +1,17 @@
+package org.diagbot.common.push.filter.pretreat;
+
+import org.diagbot.common.push.filter.PreResult;
+import org.diagbot.nlp.participle.word.Lexeme;
+import org.diagbot.nlp.participle.word.LexemePath;
+
+import java.util.List;
+
+public class PretreatmentVital extends Pretreatment {
+    public List<PreResult> analyze(String content) throws java.io.IOException{
+        return super.analyzeDefault(content);
+    }
+
+    public PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
+        return super.createDefaultPreResult(lexemes, lexeme, index);
+    }
+}

+ 40 - 1
nlp/src/main/java/org/diagbot/nlp/util/NlpUtil.java

@@ -2,7 +2,7 @@ package org.diagbot.nlp.util;
 
 import org.diagbot.nlp.participle.word.Lexeme;
 
-import java.util.Arrays;
+import java.util.*;
 
 /**
  * @Auther: fyeman
@@ -11,6 +11,20 @@ import java.util.Arrays;
  */
 public class NlpUtil {
 
+    private static List numtextList = new ArrayList(Arrays.asList("数", "多", "半", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"));
+    private static  Map<String, String> numtextMap = new HashMap<String, String>(){{
+        put("一","1");
+        put("二","2");
+        put("三","3");
+        put("四","4");
+        put("五","5");
+        put("六","6");
+        put("七","7");
+        put("八","8");
+        put("九","9");
+        put("十","10");
+    }};
+
     public static String[] extendsSymbol(String[] origin, String[] extend_symbols) {
         String[] symbols = new String[origin.length + extend_symbols.length];
         System.arraycopy(origin, 0, symbols, 0, origin.length);
@@ -33,6 +47,31 @@ public class NlpUtil {
         return false;
     }
 
+    public static double numberText2value(Lexeme l) {
+        double value = 0.0;
+        if (numtextList.contains(l.getText())) {
+            if ("数".equals(l.getText()) || "多".equals(l.getText())) {     //数年直接按5年处理
+                value = 5;
+            } else if ("半".equals(l.getText())) {
+                value = 0.5;
+            } else {
+                value = Double.valueOf(numtextMap.get(l.getText()));
+            }
+        } else {
+            try {
+                value = Double.valueOf(l.getText());
+            } catch (Exception nfe) {
+                if (l.getText().indexOf("-") > -1) {
+                    try {
+                        value = Double.valueOf(l.getText().split("-")[0]);
+                    } catch (Exception e) {
+                    }
+                }
+            }
+        }
+        return value;
+    }
+
     public static boolean isFeature(String property, NegativeEnum[] features) {
         if (property == null) {
             return false;