Sfoglia il codice sorgente

关系抽取对象解读

louhr 5 anni fa
parent
commit
0ae9411071

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

@@ -131,6 +131,35 @@ public class EntityProcess {
         return list;
     }
 
+    protected  <T> List<T> addEntity(JSONObject aiOut, EntityEnum entityType, Class<T> t, EntityEnum[] subEntityTypes, Object[] subNames) throws Exception {
+        List<T> list = new ArrayList<>();
+        List<Map<String, String>> entityList = processJson(aiOut, entityType.toString());
+        for (Map<String, String> entityMap : entityList) {
+            if (StringUtils.isEmpty(entityMap.get(entityType.toString()))) {
+                continue;
+            }
+            T o = t.newInstance();
+            for (String key : entityMap.keySet()) {
+                if (key.equals(entityType.toString())) {
+                    BeanUtils.copyProperty(o, "name", entityMap.get(key));
+                } else {
+                    for (int i = 0; i < subEntityTypes.length; i++) {
+                        if (key.equals(subEntityTypes[i].toString())) {
+                            if (subNames[i] instanceof String) {
+                                BeanUtils.copyProperty(o, subNames[i].toString(), StringUtils.isEmpty(entityMap.get(key)) ? "" : entityMap.get(key));
+                            } else {
+                                BeanUtils.copyProperty(subNames[i], "name", StringUtils.isEmpty(entityMap.get(key)) ? "" : entityMap.get(key));
+                                BeanUtils.copyProperty(o, subNames[i].getClass().getSimpleName(), subNames[i]);
+                            }
+                        }
+                    }
+                }
+            }
+            list.add(o);
+        }
+        return list;
+    }
+
 
     public String[] extract_digit(String value) {
         String[] res = new String[2];