Jelajahi Sumber

更新分词显示效果,更新对疾病的处理

MarkHuang 6 tahun lalu
induk
melakukan
921c882d4d

+ 49 - 38
nlp/src/main/java/org/diagbot/nlp/relation/analyze/StructureAnalyze.java

@@ -39,7 +39,7 @@ public class StructureAnalyze {
     private static BodyPart bodyPart = null;
     private static String num = "";
     private static String pacs_content = "";
-    private static List<String> diag_con = Arrays.asList("门诊","诊断","入院");
+    private static List<String> diag_con = Arrays.asList("门诊","诊断","入院","拟");
     private static List<String> past_con = Arrays.asList("既往","史");
     private static String colon = ":|:|提示|示";
     private static String note = "";
@@ -54,7 +54,7 @@ public class StructureAnalyze {
         String[] tokens = content.split(",|。|;");
 
         try {
-//            outputInfos.add(initOutputInfo());
+
             initialize();
             for (String token:tokens) {
 
@@ -152,7 +152,7 @@ public class StructureAnalyze {
     }
 
     public void updateInfo(OutputInfo outputInfo, Lexeme lexeme) {
-        String con = "伴";
+
         Symptom symptom = outputInfo.getSymptoms().get(outputInfo.getSymptoms().size() - 1);;
         Lis lis = null;
         Pacs pacs = null;
@@ -334,14 +334,6 @@ public class StructureAnalyze {
                                 vital.setPd(new PD());
                             }
                             pd1 = vital.getPd();
-                        } else if (current instanceof Treat) {
-                            treat = (Treat)current;
-                            if (treat.getPds() == null) {
-                                List<PD> pds1 = new ArrayList<>();
-                                pds1.add(new PD());
-                                treat.setPds(pds1);
-                            }
-                            pd1 = treat.getPds().get(0);
                         } else if (current instanceof Lis) {
                             lis = (Lis)current;
                             if (lis.getPd() == null) {
@@ -350,18 +342,31 @@ public class StructureAnalyze {
                             pd1 = lis.getPd();
                         } else if (current instanceof Past) {
                             past = (Past)current;
-                            if (past.getPds() == null) {
-                                List<PD> pds1 = new ArrayList<>();
-                                pds1.add(new PD());
+                            List<PD> pds1 = new ArrayList<>();
+                            if (past.getPds() == null || past.getPds().size() == 0) {
                                 past.setPds(pds1);
                             }
-                            pd1 = past.getPds().get(0);
+                            else { pds1 = past.getPds(); }
+                            pds1.add(new PD());
+                            pd1 = past.getPds().get(past.getPds().size() - 1);
+                        } else if (current instanceof Treat) {
+                            treat = (Treat)current;
+                            List<PD> pds1 = new ArrayList<>();
+                            if (treat.getPds() == null || treat.getPds().size() == 0) {
+                                treat.setPds(pds1);
+                            }
+                            else {
+                                pds1 = treat.getPds();
+                            }
+                            pds1.add(new PD());
+                            pd1 = treat.getPds().get(treat.getPds().size()-1);
                         }
+
+                        pd1.setValue(num);
+                        pd1.setUnit(lexeme.getText());
+                        updated = true;
+                        num = "";
                     }
-                    pd1.setValue(num);
-                    pd1.setUnit(lexeme.getText());
-                    updated = true;
-                    num = "";
                     break;
                 case Constants.word_property_time:
                     if (num.length() > 0) {
@@ -409,16 +414,14 @@ public class StructureAnalyze {
                             current_diag = "";
                             current = null;
                         }
+                        current = treat;
                     }
                     else if (past_con.indexOf(lexeme.getText()) >= 0) {
-                        outputInfo.getPasts().add(new Past());
-                        past = outputInfo.getPasts().get(outputInfo.getPasts().size() - 1);
-                        if (current_diag.length() > 0) {
-                            past.setDiagnose(current_diag);
-                            current = past;
-                            current_diag = "";
+                        if (outputInfo.getPasts() == null || outputInfo.getPasts().size() == 0) {
+                            outputInfo.getPasts().add(new Past());
                         }
-
+                        past = outputInfo.getPasts().get(outputInfo.getPasts().size() - 1);
+                        current = past;
                     }
                     break;
             }
@@ -504,7 +507,7 @@ public class StructureAnalyze {
                     } else {
                         past.setDiagnose(past.getDiagnose() + "," + name);
                     }
-                    outputInfo.getPasts().add(past);
+
                     obj = past;
                     current_treat = past;
                 }
@@ -512,23 +515,26 @@ public class StructureAnalyze {
                     if (current instanceof Treat) {
                         treat = (Treat) current;
                         /*
-                    } else if (outputInfo.getTreats().size() == 0) {
-                        outputInfo.getTreats().add(new Treat());
+                    }
+                    else {
+                        if (outputInfo.getTreats().size() == 0) {
+                            outputInfo.getTreats().add(new Treat());
+                        }
                         treat = outputInfo.getTreats().get(outputInfo.getTreats().size() - 1);
                     }
-
+                    */
                     if (treat.getDiagnose() == null || treat.getDiagnose().trim().length() == 0) {
                         treat.setDiagnose(name);
                     } else {
                         treat.setDiagnose(treat.getDiagnose() + "," + name);
                     }
-                    */
+
                     obj = treat;
                     current_treat = treat;
                 }
                 else {
                     current_diag = name;
-                    }
+                }
                 break;
             case Constants.word_property_cause:
                 Cause cause = new Cause();
@@ -617,6 +623,14 @@ public class StructureAnalyze {
 
                     obj = past;
                 }
+                else /*if (outputInfo.getTreats().size() == 0)*/ {
+                    outputInfo.getTreats().add(new Treat());
+                    treat = outputInfo.getTreats().get(outputInfo.getTreats().size() - 1);
+
+                    treat.setValue(name);
+                    current_treat = treat;
+                    obj = treat;
+                }
                 break;
             case Constants.word_property_med:
                 if (current_treat instanceof Past) {
@@ -632,11 +646,7 @@ public class StructureAnalyze {
                 }
                 else {
                     if (!(current instanceof Treat)) {
-                        if (current_treat != null && current_treat instanceof Treat) {
-                            current = current_treat;
-                        } else {
-                            current = updateClinicalInfo(outputInfo, "", Constants.word_property_diagnose);
-                        }
+                        current = updateClinicalInfo(outputInfo, "", Constants.word_property_treat);
                     }
                     treat = (Treat) current;
 
@@ -656,10 +666,11 @@ public class StructureAnalyze {
 
     public Boolean isUseful(String token) {
         Boolean useful = false;
+        String[] pacstype = {"3","17","18","19"};
         try {
             LexemePath<Lexeme> lexemes = participle(token, false);
             for (Lexeme lexeme : lexemes) {
-                if (!lexeme.getProperty().equals("99")) {
+                if (Arrays.asList(pacstype).indexOf(lexeme.getProperty())>=0) {
                     useful = true;
                     break;
                 }