Browse Source

1、提取病历信息中时间信息

louhr 5 years ago
parent
commit
0e634dd980

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

@@ -88,6 +88,9 @@ public class ParamsDataProxy {
             //提取现病史
             featuresList = fa.start(searchData.getSymptom(), FeatureType.FEATURE);
             paramFeatureInit(searchData, featuresList);
+            //提取时间信息
+            featuresList = fa.start(searchData.getSymptom(), FeatureType.TIME);
+            paramFeatureInit(searchData, featuresList);
         }
         if (!StringUtils.isEmpty(searchData.getVital())) {
             //提取体征
@@ -261,11 +264,15 @@ public class ParamsDataProxy {
                 map.put("property", String.valueOf(featureMap.get("property")));
                 map.put("concept", String.valueOf(featureMap.get("concept")));
                 if (Constants.default_negative.equals(featureMap.get("negative"))) {
-                    if (searchData.getInputs().get(map.get("feature_name")) == null) {
-                        if (i < 5) {
-                            searchData.getInputs().put(map.get("feature_name"), map);
+                    if (map.get("featureType").equals(Constants.feature_type_time)) {
+                        searchData.getInputs().put("时间", map);
+                    } else {
+                        if (searchData.getInputs().get(map.get("feature_name")) == null) {
+                            if (i < 5) {
+                                searchData.getInputs().put(map.get("feature_name"), map);
+                            }
+                            searchData.getGraphInputs().put(map.get("feature_name"), map);
                         }
-                        searchData.getGraphInputs().put(map.get("feature_name"), map);
                     }
                 } else {
                     searchData.getFilters().put(map.get("feature_name"), map);

+ 5 - 1
nlp-web/src/main/java/org/diagbot/nlp/controller/FeatureController.java

@@ -154,7 +154,10 @@ public class FeatureController extends BaseController<Feature, FeatureWrapper, L
                             content = info.getPresent();
                             propel = propelSymptom;
                             break;
-
+                        case TIME:
+                            content = info.getPresent();
+                            propel = propelSymptom;
+                            break;
                         case FEATURE:
                             content = info.getPresent();
                             propel = propelSymptom;
@@ -177,6 +180,7 @@ public class FeatureController extends BaseController<Feature, FeatureWrapper, L
                             break;
                     }
                     featureList = sa.start(content, FeatureType.parse(featureType));
+
                     if (featureList == null) {
                         continue;
                     }

+ 4 - 1
nlp/src/main/java/org/diagbot/nlp/feature/FeatureType.java

@@ -14,7 +14,8 @@ public enum FeatureType {
     FEATURE(Constants.feature_type_feature),
     TREAT(Constants.feature_type_treat),
     HISTORY(Constants.feature_type_history),
-    VITAL_INDEX(Constants.feature_type_vital_index);
+    VITAL_INDEX(Constants.feature_type_vital_index),
+    TIME(Constants.feature_type_time);
 
     FeatureType(String value) {
         this.value = value;
@@ -50,6 +51,8 @@ public enum FeatureType {
                 return FeatureType.FEATURE;
             case Constants.feature_type_vital_index:
                 return FeatureType.VITAL;
+            case Constants.feature_type_time:
+                return FeatureType.TIME;
         }
         return FeatureType.SYMPTOM;
     }

+ 2 - 2
nlp/src/main/java/org/diagbot/nlp/feature/extract/CaseToken.java

@@ -100,7 +100,7 @@ public abstract class CaseToken {
             }
         }
         if (!hasFeature) {
-//            if (sn <= 6) {
+            if (sn < 5) {
                 Map<String, Object> fMap = new HashMap<>(10);
                 fMap.put("feature_name", lexeme.getText());
                 fMap.put("feature_type", featureType);
@@ -109,7 +109,7 @@ public abstract class CaseToken {
                 fMap.put("property", lexeme.getProperty());
                 fMap.put("concept", lexeme.getConcept());
                 featuresList.add(fMap);
-//            }
+            }
         }
     }
 }

+ 6 - 0
nlp/src/main/java/org/diagbot/nlp/feature/extract/CaseTokenFactory.java

@@ -14,6 +14,7 @@ public class CaseTokenFactory {
     private static CaseTokenVital caseTokenVital = null;
     private static CaseTokenLIS caseTokenLis = null;
     private static CaseTokenPACS caseTokenPacs = null;
+    private static CaseTokenTime caseTokenTime = null;
 
     public static CaseToken getInstance(FeatureType featureType) throws java.lang.InstantiationException, java.lang.IllegalAccessException {
         try {
@@ -48,6 +49,11 @@ public class CaseTokenFactory {
                         caseTokenDiag = new CaseTokenDiag();
                     }
                     return caseTokenDiag;
+                case TIME:
+                    if (caseTokenTime == null) {
+                        caseTokenTime = new CaseTokenTime();
+                    }
+                    return caseTokenTime;
             }
         }catch (Exception ille) {
             throw ille;

+ 108 - 0
nlp/src/main/java/org/diagbot/nlp/feature/extract/CaseTokenTime.java

@@ -0,0 +1,108 @@
+package org.diagbot.nlp.feature.extract;
+
+import org.diagbot.nlp.participle.word.Lexeme;
+import org.diagbot.nlp.participle.word.LexemePath;
+import org.diagbot.nlp.util.Constants;
+import org.diagbot.nlp.util.NegativeEnum;
+import org.diagbot.nlp.util.NlpUtil;
+
+import java.math.BigDecimal;
+import java.util.*;
+
+public class CaseTokenTime extends CaseToken {
+    {
+        stop_symbol = NlpUtil.extendsSymbol(stop_symbol, new String[]{",", ",", ":", ":"});
+    }
+
+    private List numtextList = new ArrayList(Arrays.asList("数", "多", "半", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"));
+    private 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 List<Map<String, Object>> analyze(LexemePath<Lexeme> lexemePath) throws Exception {
+        super.sn = 0;
+        int max_offset = 10;        //只取前10个词元中的时间信息
+        //词性
+        String property = null;
+        NegativeEnum[] nees = new NegativeEnum[]{NegativeEnum.EVENT_TIME};
+        List<Map<String, Object>> featuresList = new ArrayList<>();
+
+        Lexeme leftLexeme = null;
+
+        double time_value = 0.0;
+        for (int index = 0; index < lexemePath.size(); index++) {
+            Lexeme lexeme = lexemePath.get(index);
+            property = lexeme.getProperty();
+            if (NlpUtil.isFeature(property, nees)) {          //特征词 化验
+                if (index > 0) {
+                    leftLexeme = lexemePath.get(index - 1);
+                } else {
+                    break;
+                }
+                if (numtextList.contains(leftLexeme.getText())) {
+                    if ("数".equals(leftLexeme.getText()) || "多".equals(leftLexeme.getText())) {     //数年直接按5年处理
+                        time_value = 5;
+                    } else if ("半".equals(leftLexeme.getText())) {
+                        time_value = 0.5;
+                    } else {
+                        time_value = Double.valueOf(numtextMap.get(leftLexeme.getText()));
+                    }
+                } else {
+                    try {
+                        time_value = Double.valueOf(leftLexeme.getText());
+                    } catch (Exception nfe) {
+                        if (leftLexeme.getText().indexOf("-") > -1) {
+                            try {
+                                time_value = Double.valueOf(leftLexeme.getText().split("-")[0]);
+                            } catch (Exception e) {
+                            }
+                        }
+                    }
+                }
+
+                if (time_value > 0) {
+                    if ("年".equals(lexeme.getText()) || "年余".equals(lexeme.getText())) {
+                        time_value = time_value * 365;
+                    } else if ("月".equals(lexeme.getText()) || "月余".equals(lexeme.getText())) {
+                        time_value = time_value * 30;
+                    } else if ("天".equals(lexeme.getText()) || "天余".equals(lexeme.getText()) || "日".equals(lexeme.getText())) {
+                        time_value = time_value;
+                    } else if ("周".equals(lexeme.getText()) || "周余".equals(lexeme.getText())) {
+                        time_value = time_value * 7;
+                    } else if ("小时".equals(lexeme.getText())) {
+                        time_value = time_value / 24;
+                    } else if ("分钟".equals(lexeme.getText())) {
+                        time_value = time_value / (24 * 60);
+                    }
+                }
+
+                if (time_value > 0) {
+                    BigDecimal bd = new BigDecimal(time_value);
+                    time_value = bd.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
+
+                    Map<String, Object> fMap = new HashMap<>(10);
+                    fMap.put("feature_name", time_value);
+                    fMap.put("feature_type", Constants.feature_type_time);
+                    fMap.put("negative", "有");
+                    fMap.put("sn", String.valueOf(sn++));
+                    fMap.put("property", lexeme.getProperty());
+                    fMap.put("concept", lexeme.getConcept());
+
+                    fMap.put("time_label", "1");
+                    featuresList.add(fMap);
+                }
+                break;
+            }
+        }
+        return featuresList;
+    }
+}

+ 1 - 0
nlp/src/main/java/org/diagbot/nlp/util/Constants.java

@@ -16,6 +16,7 @@ public class Constants {
     public final static String feature_type_treat = "6";       //治疗
     public final static String feature_type_history = "7";       //历史
     public final static String feature_type_feature = "9"; //症状描述中的特征信息 如部位、性质等
+    public final static String feature_type_time = "10";    //提取时间
     public final static String feature_type_vital_index = "42"; //体征指标
 
     public static NegativeEnum[] symptom_type = new NegativeEnum[]{NegativeEnum.SYMPTOM, NegativeEnum.SYMPTOM_INDEX, NegativeEnum.SYMPTOM_PERFORMANCE};

+ 1 - 1
push-web/src/main/resources/static/pages/extract/feature.html

@@ -99,7 +99,7 @@
                     <input type="checkbox" name="featureType" value="4"/>检验&nbsp;&nbsp;
                     <input type="checkbox" name="featureType" value="5"/>检查&nbsp;&nbsp;
                     <input type="checkbox" name="featureType" value="9"/>特征&nbsp;&nbsp;
-
+                    <input type="checkbox" name="featureType" value="10"/>时间&nbsp;&nbsp;
                     <button type="button" class="btn btn-success pull-right" onclick="_ajax('/feature/generate')"><i
                             class="fa fa-credit-card"></i> 提取
                     </button>