Explorar el Código

既往史关系抽取 编译有误

louhr hace 5 años
padre
commit
d5e98edbe5

+ 25 - 0
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/process/EntityProcess.java

@@ -3,6 +3,9 @@ package com.lantone.qc.kernel.structure.ai.process;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.lantone.qc.kernel.structure.ai.model.CrfOut;
+import com.lantone.qc.kernel.structure.ai.model.EntityEnum;
+import com.lantone.qc.pub.model.entity.Negative;
+import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import java.util.ArrayList;
@@ -106,6 +109,28 @@ public class EntityProcess {
         return entityRelationPair;
     }
 
+    protected  <T> List<T> addEntity(JSONObject aiOut, EntityEnum entityType, Class<T> t) throws Exception {
+        List<T> list = new ArrayList<>();
+        List<Map<String, String>> pastEntityList = processJson(aiOut, entityType.toString());
+        for (Map<String, String> pastEntityMap : pastEntityList) {
+            if (StringUtils.isEmpty(pastEntityMap.get(entityType.toString()))) {
+                continue;
+            }
+            T o = t.newInstance();
+            for (String key : pastEntityMap.keySet()) {
+                if (key.equals(entityType.toString())) {
+                    BeanUtils.copyProperty(o, "name", pastEntityMap.get(key));
+                } else if (key.equals(EntityEnum.NEGATIVE.toString())) {
+                    Negative negative = new Negative();
+                    negative.setName(StringUtils.isEmpty(pastEntityMap.get(key)) ? "" : pastEntityMap.get(key));
+                    BeanUtils.copyProperty(o, "negative", negative);
+                }
+            }
+            list.add(o);
+        }
+        return list;
+    }
+
 
     public String[] extract_digit(String value) {
         String[] res = new String[2];

+ 4 - 23
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/process/EntityProcessPast.java

@@ -4,7 +4,9 @@ import com.alibaba.fastjson.JSONObject;
 import com.lantone.qc.kernel.structure.ai.model.CrfOut;
 import com.lantone.qc.kernel.structure.ai.model.EntityEnum;
 import com.lantone.qc.pub.model.entity.Negative;
+import com.lantone.qc.pub.model.entity.Operation;
 import com.lantone.qc.pub.model.entity.Past;
+import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import java.util.ArrayList;
@@ -19,12 +21,13 @@ public class EntityProcessPast extends EntityProcess {
     public static String blood_history = "输血史";
     public static String vaccination_history = "预防接种史";
     public static String infect_history = "传染病史";
-    @Override
+
     public void extractEntity(JSONObject outputs, CrfOut outputInfo) {
         List<Past> pasts = new ArrayList<>();
         //疾病史
         addPast(outputs, pasts);
         //手术史
+        addPast(outputs, EntityEnum.OPERATION, Operation.class);
         addPast(outputs, pasts, EntityEnum.OPERATION, 1, EntityProcessPast.surgery_history);
         addPast(outputs, pasts, EntityEnum.OPERATION_KEYWORD, 1, EntityProcessPast.surgery_history);
 
@@ -96,26 +99,4 @@ public class EntityProcessPast extends EntityProcess {
             pasts.add(past);
         }
     }
-    private void addPast(JSONObject outputs, List<Past> pasts, EntityEnum entityType, int pastType, String pastTypeString) {
-        Past past = null;
-        List<Map<String, String>> pastEntityList = processJson(outputs, entityType.toString());
-        for (Map<String, String> pastEntityMap : pastEntityList) {
-            if (StringUtils.isEmpty(pastEntityMap.get(entityType.toString()))) {
-                continue;
-            }
-            past = new Past();
-            for (String key : pastEntityMap.keySet()) {
-                if (key.equals(entityType.toString())) {
-                    past.setType(pastType);
-                    past.setTitle(pastTypeString);
-                    past.setValue(pastEntityMap.get(key));
-                } else if (key.equals(EntityEnum.NEGATIVE.toString())) {
-                    Negative negative = new Negative();
-                    negative.setName(StringUtils.isEmpty(pastEntityMap.get(key)) ? "" : pastEntityMap.get(key));
-                    past.setNegative(negative);
-                }
-            }
-            pasts.add(past);
-        }
-    }
 }