Selaa lähdekoodia

更新分词显示效果

MarkHuang 6 vuotta sitten
vanhempi
commit
151832294b

+ 31 - 51
nlp/src/main/java/org/diagbot/nlp/relation/analyze/StructureAnalyze.java

@@ -57,13 +57,11 @@ public class StructureAnalyze {
                     updateLexeme(lexeme);
                     updateInfo(outputInfo, lexeme);
                 }
-//                outputInfo.getSymptoms().get(outputInfo.getSymptoms().size()-1).setSymptomName(token);
 
-                Symptom symptom = outputInfos.get(outputInfos.size() - 1).getSymptoms().get(0);
-//                if (symptom.getNegative() != null && symptom.getSymptomName() == "") {
-//                    outputInfos.get(outputInfos.size() - 1).setSymptoms(new ArrayList<>());
-//                }
-                if (updated == false) {
+//                Symptom symptom = outputInfos.get(outputInfos.size() - 1).getSymptoms().get(0);
+
+                if (updated == false ||
+                        (getPropsize(outputInfo) == 1 && outputInfo.getSymptoms().get(0).getSymptomName().trim().length() == 0)){
                     outputInfos.remove(outputInfos.size() - 1);
                 }
             }
@@ -105,15 +103,6 @@ public class StructureAnalyze {
 
             switch (lexeme.getProperty()) {
                 case Constants.word_property_cause:
-                    Cause cause = new Cause();
-                    cause.setCauseName(lexeme.getText());
-                    if (current instanceof Symptom) {
-                        symptom = (Symptom)current;
-                    }
-                    symptom.setCause(cause);
-                    current = symptom;
-                    updated = true;
-                    break;
                 case Constants.word_property_symptom:
                 case Constants.word_property_vital_idx:
                     current = updateClinicalInfo(outputInfo, lexeme.getText(), lexeme.getProperty());
@@ -315,14 +304,22 @@ public class StructureAnalyze {
         return outputInfo;
     }
 
+    public int getPropsize(OutputInfo outputInfo) {
+        int size = outputInfo.getSymptoms().size() + outputInfo.getLises().size() + outputInfo.getTreats().size()
+                + outputInfo.getVitals().size() + outputInfo.getPacses().size();
+
+        return size;
+    }
+
 
     public Object updateClinicalInfo(OutputInfo outputInfo, String name, String type) {
 
         Object obj = null;
+        Symptom symptom = null;
 
         switch (type) {
             case Constants.word_property_symptom:
-                Symptom symptom = outputInfo.getSymptoms().get(outputInfo.getSymptoms().size() - 1);
+                symptom = outputInfo.getSymptoms().get(outputInfo.getSymptoms().size() - 1);
 
                 if (symptom.getSymptomName() == null || symptom.getSymptomName().trim().length() == 0) {
                     symptom.setSymptomName(name);
@@ -364,47 +361,30 @@ public class StructureAnalyze {
                 }
                 obj = treat;
                 break;
-        }
-        /*
-//        if (symptom.getSymptomName().trim().length() == 0) {
-            if (outputInfos.size() >= 2 ) {
-                if (symptom.getNegative() == null &&
-                        (outputInfos.get(outputInfos.size() - 2).getSymptoms().get(0).getSymptomName().length() > 0 ||
-                        outputInfos.get(outputInfos.size() - 2).getSymptoms().get(0).getNegative() != null)) {
-                    symptom = outputInfos.get(outputInfos.size() - 2).getSymptoms().get(0);
-                    if (symptom.getSymptomName().indexOf(name) == -1) {
-                        symptom.setSymptomName(symptom.getSymptomName() + ", " + name);
-                    }
-                    outputInfos.remove(outputInfos.get(outputInfos.size() - 1));
-                }
-                else if (symptom.getNegative() != null &&
-                        outputInfos.get(outputInfos.size() - 2).getSymptoms().get(0).getNegative() != null) {
-                    symptom = outputInfos.get(outputInfos.size() - 2).getSymptoms().get(0);
-                    if (symptom.getSymptomName().indexOf(name) == -1) {
-                        symptom.setSymptomName(symptom.getSymptomName() + ", " + name);
-                    }
-                    outputInfos.remove(outputInfos.get(outputInfos.size() - 1));
+            case Constants.word_property_cause:
+                Cause cause = new Cause();
+                cause.setCauseName(name);
+
+                if (current instanceof Symptom) {
+                    symptom = (Symptom)current;
                 }
                 else {
-                    symptom.setSymptomName(name);
+                    symptom = outputInfo.getSymptoms().get(outputInfo.getSymptoms().size() - 1);
                 }
-            }
-            else {
 
-                if (symptom.getSymptomName().trim().length() == 0) {
-                    symptom.setSymptomName(name);
-                }
-                else {
-                    symptom.setSymptomName(symptom.getSymptomName() + ", " + name);
+                if (symptom.getCause() != null) {
+                    if (!outputInfo.getSymptoms().get(outputInfo.getSymptoms().size() - 1).getSymptomName().equals(symptom.getSymptomName())) {
+                        outputInfo.getSymptoms().get(outputInfo.getSymptoms().size() - 1).setSymptomName(symptom.getSymptomName());
+                        symptom = outputInfo.getSymptoms().get(outputInfo.getSymptoms().size() - 1);
+                    }
                 }
+                symptom.setCause(cause);
+
+                obj = symptom;
+
+                break;
+        }
 
-            }
-//        }
-//        else {
-//            symptom.setSymptomName(symptom.getSymptomName() + ", " + name);
-//        }
-*/
-//        current = symptom;
         return obj;
     }