|
@@ -5,6 +5,7 @@ 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.kernel.structure.ai.model.Lemma;
|
|
|
+import com.lantone.qc.kernel.structure.ai.model.Relation;
|
|
|
import com.lantone.qc.pub.model.entity.DiagInfectious;
|
|
|
import com.lantone.qc.pub.model.entity.Negative;
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
@@ -76,10 +77,11 @@ public class EntityProcess {
|
|
|
* @param relations
|
|
|
*/
|
|
|
private void findRelationLemma(Lemma lemma, List<Lemma> allLemmaList, JSONArray relations) {
|
|
|
- List<Integer> connectEntityIdList = getConnectEntityIdList(lemma.getId(), relations);
|
|
|
+ List<Relation> connectEntityIdList = getConnectEntityList(lemma.getId(), relations);
|
|
|
for (Lemma l : allLemmaList) {
|
|
|
- for (Integer reId : connectEntityIdList) {
|
|
|
- if (l.getId() == reId) {
|
|
|
+ for (Relation relation : connectEntityIdList) {
|
|
|
+ if (l.getId() == relation.getId()) {
|
|
|
+ l.setRelationName(relation.getRelationName());
|
|
|
findRelationLemma(l, allLemmaList, relations);
|
|
|
lemma.addRelationLemmas(l);
|
|
|
}
|
|
@@ -107,13 +109,13 @@ public class EntityProcess {
|
|
|
JSONObject entity = entitys.getJSONObject(i);
|
|
|
if (entityType.equals(entity.getString("name"))) {
|
|
|
int id = entity.getIntValue("id");
|
|
|
- List<Integer> connectEntityIdList = getConnectEntityIdList(id, relations);
|
|
|
- if (connectEntityIdList.size() == 0) {
|
|
|
+ List<Relation> connectEntityRelationList = getConnectEntityList(id, relations);
|
|
|
+ if (connectEntityRelationList.size() == 0) {
|
|
|
connectEntity = new HashMap<>();
|
|
|
connectEntity.put(entity.getString("name"), entity.getString("value"));
|
|
|
connectEntityList.add(connectEntity);
|
|
|
} else {
|
|
|
- connectEntity = getConnectEntity(connectEntityIdList, entitys);
|
|
|
+ connectEntity = getConnectEntity(connectEntityRelationList, entitys);
|
|
|
connectEntity.put(entity.getString("name"), entity.getString("value"));
|
|
|
connectEntityList.add(connectEntity);
|
|
|
}
|
|
@@ -129,21 +131,27 @@ public class EntityProcess {
|
|
|
* @param relations 关系抽取出的关系对
|
|
|
* @return connectEntityIdList 有关系实体的id列表(List)
|
|
|
*/
|
|
|
- public List<Integer> getConnectEntityIdList(int entityId, JSONArray relations) {
|
|
|
- List<Integer> connectEntityIdList = new ArrayList<>();
|
|
|
+ public List<Relation> getConnectEntityList(int entityId, JSONArray relations) {
|
|
|
+ List<Relation> connectEntityList = new ArrayList<>();
|
|
|
for (int i = 0; i < relations.size(); i++) {
|
|
|
if (StringUtils.isEmpty(relations.get(i).toString())) {
|
|
|
continue;
|
|
|
}
|
|
|
- JSONObject relation = relations.getJSONObject(i);
|
|
|
- if (relation.getIntValue("from") == entityId) {
|
|
|
- connectEntityIdList.add(relation.getIntValue("to"));
|
|
|
+ JSONObject relationObjs = relations.getJSONObject(i);
|
|
|
+ if (relationObjs.getIntValue("from") == entityId) {
|
|
|
+ Relation relation = new Relation();
|
|
|
+ relation.setId(relationObjs.getIntValue("to"));
|
|
|
+ relation.setRelationName(relationObjs.getString("name"));
|
|
|
+ connectEntityList.add(relation);
|
|
|
}
|
|
|
- if (relation.getIntValue("to") == entityId) {
|
|
|
- connectEntityIdList.add(relation.getIntValue("from"));
|
|
|
+ if (relationObjs.getIntValue("to") == entityId) {
|
|
|
+ Relation relation = new Relation();
|
|
|
+ relation.setId(relationObjs.getIntValue("from"));
|
|
|
+ relation.setRelationName(relationObjs.getString("name"));
|
|
|
+ connectEntityList.add(relation);
|
|
|
}
|
|
|
}
|
|
|
- return connectEntityIdList;
|
|
|
+ return connectEntityList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -169,15 +177,15 @@ public class EntityProcess {
|
|
|
* @param entitys 关系抽取的实体列表
|
|
|
* @return entityRelationPair 实体id列表对应的所有实体类型及实体值
|
|
|
*/
|
|
|
- public Map<String, String> getConnectEntity(List<Integer> connectEntityIdList, JSONArray entitys) {
|
|
|
+ public Map<String, String> getConnectEntity(List<Relation> connectEntityIdList, JSONArray entitys) {
|
|
|
Map<String, String> entityRelationPair = new HashMap<>();
|
|
|
- for (int connectEntityId : connectEntityIdList) {
|
|
|
+ for (Relation connectEntityId : connectEntityIdList) {
|
|
|
for (int i = 0; i < entitys.size(); i++) {
|
|
|
if (StringUtils.isEmpty(entitys.get(i).toString())) {
|
|
|
continue;
|
|
|
}
|
|
|
JSONObject entity = entitys.getJSONObject(i);
|
|
|
- if (connectEntityId == entity.getIntValue("id")) {
|
|
|
+ if (connectEntityId.getId() == entity.getIntValue("id")) {
|
|
|
if (entityRelationPair.containsKey(entity.getString("name"))) {
|
|
|
entityRelationPair.put(entity.getString("name"),
|
|
|
entityRelationPair.get(entity.getString("name")) + "," + entity.getString("value"));
|