|
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.pavis.backend.slim.common.utils.CommonUtils;
|
|
|
import com.pavis.backend.slim.common.utils.SecurityUtils;
|
|
|
import com.pavis.backend.slim.project.system.client.AlgKgClient;
|
|
|
+import com.pavis.backend.slim.project.system.domain.AnnotationList;
|
|
|
import com.pavis.backend.slim.project.system.domain.EntityForAlg;
|
|
|
import com.pavis.backend.slim.project.system.domain.EntityLabelsRelation;
|
|
|
import com.pavis.backend.slim.project.system.domain.SysEntity;
|
|
@@ -21,6 +22,7 @@ import com.pavis.backend.slim.project.system.domain.annotation.RelationForAlg;
|
|
|
import com.pavis.backend.slim.project.system.domain.annotation.SchemaImport;
|
|
|
import com.pavis.backend.slim.project.system.domain.annotation.ToAnnotation;
|
|
|
import com.pavis.backend.slim.project.system.domain.annotation.UniversalGgraphToAlg;
|
|
|
+import com.pavis.backend.slim.project.system.mapper.AnnotationListMapper;
|
|
|
import com.pavis.backend.slim.project.system.mapper.EntityLabelsRelationMapper;
|
|
|
import com.pavis.backend.slim.project.system.service.EntityLablesRelationService;
|
|
|
import com.pavis.backend.slim.project.system.service.EntityLablesSpanService;
|
|
@@ -70,6 +72,9 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
|
|
|
@Autowired
|
|
|
private GenerateGraphService generateGraphService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AnnotationListMapper annotationListMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public EntityLabelsRelation saveAnnotationRelation(AnnotationEntityRelation relation) {
|
|
|
EntityLabelsRelation entityLabelsRelation = new EntityLabelsRelation();
|
|
@@ -89,9 +94,12 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
|
|
|
// 1.根据fileId获取文本信息text、历史标注的实体信息列表、历史标注的实体间关系信息列表。
|
|
|
// List<TreeFile> treeFiles = sysFileService.listTreeFiles(kgId);
|
|
|
// log.info("获取知识库下的文档信息treeFiles:{}",JSON.toJSONString(treeFiles));
|
|
|
- String fileTextContent = sysFileService.getFileTextContent(fileId);
|
|
|
- if (null != fileTextContent && StringUtils.isNotBlank(fileTextContent)) {
|
|
|
- log.info("文本内容不为空:{}", fileTextContent);
|
|
|
+ // String fileTextContent = sysFileService.getFileTextContent(fileId);
|
|
|
+ List<AnnotationList> annotationLists = annotationListMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getKgId, kgId).eq(AnnotationList::getFileId, fileId));
|
|
|
+ // log.info("fileTextContent:{}",fileTextContent);
|
|
|
+ // if (null != fileTextContent && StringUtils.isNotBlank(fileTextContent)) {
|
|
|
+ if (!CollectionUtils.isEmpty(annotationLists) && null != annotationLists.get(0).getTextContent() && StringUtils.isNotBlank(annotationLists.get(0).getTextContent())) {
|
|
|
+ // log.info("文本内容不为空:{}", annotationLists.get(0).getTextContent());
|
|
|
// 1.1 获取历史标注实体信息数据列表。
|
|
|
List<AnnotationEntity> entities = entityLablesSpanService.getAnnotationEntityByKgIdAndFileId(kgId, fileId);
|
|
|
// 1.2 获取历史标注实体间关系数据列表。
|
|
@@ -101,7 +109,7 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
|
|
|
List<SysEntity> entityLists = sysEntityService.getEntityByKgId(kgId);
|
|
|
// 3.根据kgId获取知识库下的所有实体间关系信息列表。
|
|
|
List<SysRelation> relationLists = sysRelationService.getRelationByKgId(kgId);
|
|
|
- ToAnnotation toAnnotation = ToAnnotation.builder().text(fileTextContent).entities(entities).relations(relations)
|
|
|
+ ToAnnotation toAnnotation = ToAnnotation.builder().text(annotationLists.get(0).getTextContent()).entities(entities).relations(relations)
|
|
|
.entityList(entityLists).relationList(relationLists).build();
|
|
|
return toAnnotation;
|
|
|
}
|
|
@@ -142,7 +150,7 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
|
|
|
// todo 直接调用算法获取taskId,type=true。返回json{"taskId":""}。生成一条记录。
|
|
|
log.info("生成图谱接口 ---->无图schema 通用图谱调用中...");
|
|
|
UniversalGgraphToAlg universalGgraphToAlg = UniversalGgraphToAlg.builder().kgId(kgId).fileIds(fileIds).taskType(true).build();
|
|
|
- String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(JSON.toJSONString(universalGgraphToAlg));
|
|
|
+ String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(universalGgraphToAlg);
|
|
|
createGenerateGraph(getTaskIdRes, kgId, true, 0, 0);
|
|
|
} catch (Exception ex) {
|
|
|
ex.printStackTrace();
|
|
@@ -159,7 +167,7 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
|
|
|
log.info("有图schema的实体间关系信息:{}",JSON.toJSONString(relationForAlgs));
|
|
|
SchemaImport schemaImport = SchemaImport.builder().kgId(kgId).entityList(entityForAlgs).relationList(relationForAlgs).build();
|
|
|
log.info("调用算法服务的schemaImport服务发送实体和关系属性数据:{}",JSON.toJSONString(schemaImport));
|
|
|
- String schemaImportRes = algKgClient.sendEntityRelationToAlg(JSON.toJSONString(schemaImport));
|
|
|
+ String schemaImportRes = algKgClient.sendEntityRelationToAlg(schemaImport);
|
|
|
log.info("调用算法服务的schemaImport服务发送实体和关系属性数据结果 schemaImportRes:{}",JSON.toJSONString(schemaImportRes));
|
|
|
if ("ok".equals(schemaImportRes)){
|
|
|
// 2.2 todo 当前版本已弃用: 如果该图谱的创建了实体和关系数据,则调用算法的生成图谱服务,即入参为:text、实体标注数据列表、实体关系标注数据列表。
|
|
@@ -168,18 +176,24 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
|
|
|
// 3.判断是否存在标注数据:有标注数据:请求labels/import,返回OK,继续调用获取taskId;
|
|
|
AnnotationToAlg annotationToAlg = AnnotationToAlg.builder().kgId(kgId).annotationDatas(annotationDatas).build();// 算法所需数据结构。
|
|
|
log.info("标注数据待发送至算法数据结构annotationToAlg:{}", JSON.toJSONString(annotationToAlg));
|
|
|
+ log.info("is json annotationToAlg:{}",CommonUtils.isJson(JSON.toJSONString(annotationToAlg)));
|
|
|
+ log.info("----------------------------------------------------");
|
|
|
if (!CollectionUtils.isEmpty(annotationDatas) && annotationDatas.get(0).getEntities().size() > 0) {
|
|
|
log.info("有图schema 有标注数据");
|
|
|
// 3.1 有标注数据:请求/labels/import,返回OK,继续调用/graph/create_graph获取taskId;
|
|
|
// todo 3.1.1 发送数据给算法。
|
|
|
String algRes = null;
|
|
|
try {
|
|
|
- algRes = algKgClient.sendToAlgForGenerateKgGraph(JSON.toJSONString(annotationToAlg));
|
|
|
+ // algRes = algKgClient.sendToAlgForGenerateKgGraph(JSON.toJSONString(annotationToAlg));
|
|
|
+ log.info("调用算法标注服务前入参:{}",JSONArray.toJSONString(annotationToAlg));
|
|
|
+ // algRes = algKgClient.sendToAlgForGenerateKgGraph(JSONArray.toJSONString(annotationToAlg));
|
|
|
+ algRes = algKgClient.sendToAlgForGenerateKgGraph(annotationToAlg);
|
|
|
+
|
|
|
log.info("该图谱存在实体关系数据时发送标注数据列表,调用算法生成知识图谱接口返回algRes:{}", algRes);
|
|
|
if (null != algRes && "ok".equals(algRes)) {
|
|
|
// todo 调用算法获取taskId,type=false。返回json{"taskId":""}。生成一条记录。状态为200.才调用。
|
|
|
UniversalGgraphToAlg universalGgraphToAlg = UniversalGgraphToAlg.builder().kgId(kgId).fileIds(fileIds).taskType(false).build();
|
|
|
- String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(JSON.toJSONString(universalGgraphToAlg));
|
|
|
+ String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(universalGgraphToAlg);
|
|
|
createGenerateGraph(getTaskIdRes, kgId, false, 1, annotationDatas.size() > 0 ? 1 : 0);
|
|
|
}
|
|
|
} catch (Exception ex) {
|
|
@@ -190,7 +204,7 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
|
|
|
// 3.2 无标注数据:请求graph/create_graph获取taskId。
|
|
|
log.info("有图schema 但无标注数据");
|
|
|
UniversalGgraphToAlg universalGgraphToAlg = UniversalGgraphToAlg.builder().kgId(kgId).fileIds(fileIds).taskType(false).build();
|
|
|
- String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(JSON.toJSONString(universalGgraphToAlg));
|
|
|
+ String getTaskIdRes = algKgClient.afterSendAnnotationToGetTaskId(universalGgraphToAlg);
|
|
|
createGenerateGraph(getTaskIdRes, kgId, false, 0, 0);
|
|
|
}
|
|
|
return annotationToAlg;
|
|
@@ -208,8 +222,10 @@ public class EntityLabelsRelationServiceImpl extends ServiceImpl<EntityLabelsRel
|
|
|
List<AnnotationData> annotationDatas = new ArrayList<>();// 图谱下的所有文档标注信息。
|
|
|
for (String fileId : fileIds) {
|
|
|
String fileTextContent = sysFileService.getFileTextContent(fileId);
|
|
|
+ // List<AnnotationList> annotationLists = annotationListMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getKgId, kgId).eq(AnnotationList::getFileId, fileId));
|
|
|
+ // fileTextContent = !CollectionUtils.isEmpty(annotationLists) ? annotationLists.get
|
|
|
if (null != fileTextContent && StringUtils.isNotBlank(fileTextContent)) {
|
|
|
- log.info("文本内容不为空:{}", fileTextContent);
|
|
|
+ // log.info("文本内容不为空:{}", fileTextContent);
|
|
|
log.info("--->fileId:{}", fileId);
|
|
|
// 获取历史标注实体信息数据列表,即知识库下的实体标注信息列表。
|
|
|
List<AnnotationEntity> entities = entityLablesSpanService.getAnnotationEntityByKgIdAndFileId(kgId, fileId);
|