初始化代码
parent
b8418fc60c
commit
b9c957a74a
@ -0,0 +1,63 @@
|
||||
package com.supervision.pdfqaserver.config;
|
||||
|
||||
import com.supervision.pdfqaserver.constant.ResultStatusEnum;
|
||||
import com.supervision.pdfqaserver.dto.R;
|
||||
import com.supervision.pdfqaserver.exception.BusinessException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
||||
|
||||
/**
|
||||
* 统一异常处理器配置
|
||||
*
|
||||
* @author wb
|
||||
* @date 2022/3/10 13:24
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@RestControllerAdvice(annotations = RestController.class, basePackages = {"com.supervision.ai.service.**.controller"})
|
||||
public class ExceptionHandlerConfig {
|
||||
|
||||
/**
|
||||
* 添加手动校验参数的异常处理
|
||||
*
|
||||
* @param exception 参数验证异常
|
||||
* @return 通用返回值
|
||||
*/
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
public R<?> manualValidationExceptionResponse(IllegalArgumentException exception) {
|
||||
log.error("=========手动校验参数异常=========>>>");
|
||||
log.error(exception.getMessage(), exception);
|
||||
log.error("<<<=========手动校验参数异常=========");
|
||||
return R.fail(ResultStatusEnum.ILLEGAL_ARGUMENT.getCode(), exception.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public R<?> businessExceptionResponse(BusinessException exception) {
|
||||
log.error("=========运行异常=========>>>");
|
||||
log.error(exception.getMessage(), exception);
|
||||
log.error("<<<=========运行异常=========");
|
||||
|
||||
return R.fail(511, exception.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public R<?> manualValidationExceptionResponse(RuntimeException exception) {
|
||||
log.error("=========运行异常=========>>>");
|
||||
log.error(exception.getMessage(), exception);
|
||||
log.error("<<<=========运行异常=========");
|
||||
|
||||
return R.fail(ResultStatusEnum.RUNTIME_EXCEPTION.getCode(), exception.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(MaxUploadSizeExceededException.class)
|
||||
public R<?> handleMaxSizeException(MaxUploadSizeExceededException exception) {
|
||||
log.error("=========文件大小超出限制异常=========>>>");
|
||||
log.error(exception.getMessage(), exception);
|
||||
log.error("<<<=========文件大小超出限制异常=========");
|
||||
return R.fail(ResultStatusEnum.EXCEED_FILE_SIZE.getCode(), exception.getMessage());
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.supervision.pdfqaserver.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author Ray
|
||||
*/
|
||||
public class MyMetaObjectHandler implements MetaObjectHandler {
|
||||
public MyMetaObjectHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
|
||||
this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.supervision.pdfqaserver.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* MybatisPlus配置
|
||||
*
|
||||
* @author qmy
|
||||
* @version 1.0.0 2020/10/22 9:47
|
||||
* @since JDK1.8
|
||||
*/
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
@Bean
|
||||
public MyMetaObjectHandler myMetaObjectHandler() {
|
||||
return new MyMetaObjectHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截器配置
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(this.paginationInterceptor());
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
private PaginationInnerInterceptor paginationInterceptor() {
|
||||
PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
|
||||
paginationInterceptor.setOverflow(false);
|
||||
/**
|
||||
* 注意! 此处要设置数据库类型.
|
||||
*/
|
||||
paginationInterceptor.setDbType(DbType.POSTGRE_SQL);
|
||||
return paginationInterceptor;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.supervision.pdfqaserver.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 中英文对照字典
|
||||
* @TableName chinese_english_words
|
||||
*/
|
||||
@TableName(value ="chinese_english_words")
|
||||
@Data
|
||||
public class ChineseEnglishWords implements Serializable {
|
||||
/**
|
||||
* 中文
|
||||
*/
|
||||
@TableId
|
||||
private String chineseWord;
|
||||
|
||||
/**
|
||||
* 英文
|
||||
*/
|
||||
private String englishWord;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.supervision.pdfqaserver.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 文档切分表
|
||||
* @TableName document_truncation
|
||||
*/
|
||||
@TableName(value ="document_truncation")
|
||||
@Data
|
||||
public class DocumentTruncation implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 文档id(pdf_info表的id)
|
||||
*/
|
||||
private Integer documentId;
|
||||
|
||||
/**
|
||||
* 段落id pdf_analysis_output表的id
|
||||
*/
|
||||
private String sectionId;
|
||||
|
||||
/**
|
||||
* 布局类型 0-文本 1-表格
|
||||
*/
|
||||
private String layoutType;
|
||||
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 片段内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.supervision.pdfqaserver.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* pdf信息
|
||||
* @TableName pdf_info
|
||||
*/
|
||||
@TableName(value ="pdf_info")
|
||||
@Data
|
||||
public class PdfInfo implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* pdf路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
private String filename;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.supervision.pdfqaserver.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 片段实体抽取
|
||||
* @TableName truncation_entity_extraction
|
||||
*/
|
||||
@TableName(value ="truncation_entity_extraction")
|
||||
@Data
|
||||
public class TruncationEntityExtraction implements Serializable {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 片段id document_truncation表的id
|
||||
*/
|
||||
private String truncationId;
|
||||
|
||||
/**
|
||||
* 标签(实体类型)
|
||||
*/
|
||||
private String entity;
|
||||
|
||||
/**
|
||||
* 实体名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.supervision.pdfqaserver.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 片段关系抽取
|
||||
* @TableName truncation_relation_extraction
|
||||
*/
|
||||
@TableName(value ="truncation_relation_extraction")
|
||||
@Data
|
||||
public class TruncationRelationExtraction implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String truncationId;
|
||||
|
||||
/**
|
||||
* 头节点
|
||||
*/
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 头节点类型
|
||||
*/
|
||||
private String sourceType;
|
||||
|
||||
/**
|
||||
* 尾节点
|
||||
*/
|
||||
private String target;
|
||||
|
||||
/**
|
||||
* 尾节点类型
|
||||
*/
|
||||
private String targetType;
|
||||
|
||||
/**
|
||||
* 关系
|
||||
*/
|
||||
private String relation;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package com.supervision.pdfqaserver.dto;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 实体关系抽取
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
public class EREDTO {
|
||||
|
||||
private List<EntityExtractionDTO> entities;
|
||||
|
||||
private List<RelationExtractionDTO> relations;
|
||||
|
||||
public EREDTO() {
|
||||
}
|
||||
|
||||
public static EREDTO fromTextJson(String json,String truncationId) {
|
||||
EREDTO eredto = new EREDTO();
|
||||
JSONObject jsonObject = JSONObject.parseObject(json);
|
||||
JSONArray nodes = jsonObject.getJSONArray("nodes");
|
||||
JSONArray relations = jsonObject.getJSONArray("relations");
|
||||
List<EntityExtractionDTO> entities = new ArrayList<>();
|
||||
List<RelationExtractionDTO> relationsList = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(nodes)){
|
||||
for (Object node : nodes) {
|
||||
JSONObject nodeJson = (JSONObject) node;
|
||||
String name = nodeJson.getString("name");
|
||||
String type = nodeJson.getString("type");
|
||||
JSONObject attributes = nodeJson.getJSONObject("attributes");
|
||||
if (CollUtil.isNotEmpty(attributes)){
|
||||
List<ERAttributeDTO> erAttributeDTOS = new ArrayList<>();
|
||||
for (String key : attributes.keySet()) {
|
||||
Object value = attributes.get(key);
|
||||
String valueString = attributes.getString(key);
|
||||
ERAttributeDTO erAttributeDTO = new ERAttributeDTO(key, valueString, value instanceof Number?"1":"0");
|
||||
erAttributeDTOS.add(erAttributeDTO);
|
||||
}
|
||||
EntityExtractionDTO entityExtraction = new EntityExtractionDTO(truncationId,name,type, erAttributeDTOS);
|
||||
entities.add(entityExtraction);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(relations)){
|
||||
for (Object relation : relations) {
|
||||
JSONObject relationJson = (JSONObject) relation;
|
||||
String source = relationJson.getString("source");
|
||||
String target = relationJson.getString("target");
|
||||
String type = relationJson.getString("type");
|
||||
JSONObject attributes = relationJson.getJSONObject("attributes");
|
||||
if (CollUtil.isNotEmpty(attributes)){
|
||||
List<ERAttributeDTO> erAttributeDTOS = new ArrayList<>();
|
||||
for (String key : attributes.keySet()) {
|
||||
Object value = attributes.get(key);
|
||||
String valueString = attributes.getString(key);
|
||||
ERAttributeDTO erAttributeDTO = new ERAttributeDTO(key, valueString, value instanceof Number?"1":"0");
|
||||
erAttributeDTOS.add(erAttributeDTO);
|
||||
}
|
||||
if (StrUtil.isEmpty(source) || StrUtil.isEmpty(target)){
|
||||
log.warn("truncationId:{} relation:{} 关系中source or target is empty",truncationId,relationJson);
|
||||
continue;
|
||||
}
|
||||
Optional<EntityExtractionDTO> sourceTypeOpt = entities.stream().filter(e -> StrUtil.equals(e.getEntity(), source)).findFirst();
|
||||
if (sourceTypeOpt.isEmpty()){
|
||||
log.warn("truncationId:{} relation:{} 关系中source在实体中不存在",truncationId,relationJson);
|
||||
continue;
|
||||
}
|
||||
Optional<EntityExtractionDTO> targetTypeOpt = entities.stream().filter(e -> StrUtil.equals(e.getEntity(), target)).findFirst();
|
||||
if (targetTypeOpt.isEmpty()){
|
||||
log.warn("truncationId:{} relation:{} 关系中target在实体中不存在",truncationId,relationJson);
|
||||
continue;
|
||||
}
|
||||
RelationExtractionDTO relationExtractionDTO = new RelationExtractionDTO(truncationId,source,
|
||||
sourceTypeOpt.get().getEntity(),type,target,targetTypeOpt.get().getEntity(), erAttributeDTOS);
|
||||
relationsList.add(relationExtractionDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
eredto.setEntities(entities);
|
||||
eredto.setRelations(relationsList);
|
||||
return eredto;
|
||||
}
|
||||
|
||||
public static EREDTO fromTableJson(String json,String truncationId) {
|
||||
|
||||
EREDTO eredto = new EREDTO();
|
||||
JSONObject jsonObject = JSONObject.parseObject(json);
|
||||
JSONArray tables = jsonObject.getJSONArray("table_data");
|
||||
|
||||
if (CollUtil.isEmpty(tables)){
|
||||
return eredto;
|
||||
}
|
||||
List<EntityExtractionDTO> entities = new ArrayList<>();
|
||||
for (Object table : tables) {
|
||||
JSONObject tableJson = (JSONObject) table;
|
||||
if (CollUtil.isEmpty(tableJson)){
|
||||
continue;
|
||||
}
|
||||
EntityExtractionDTO entityExtractionDTO = new EntityExtractionDTO();
|
||||
entityExtractionDTO.setEntity("row");
|
||||
entityExtractionDTO.setName("row");
|
||||
entityExtractionDTO.setTruncationId(truncationId);
|
||||
List<ERAttributeDTO> erAttributeDTOS = new ArrayList<>();
|
||||
for (Map.Entry<String, Object> tableEntry : tableJson.entrySet()) {
|
||||
String key = tableEntry.getKey();
|
||||
Object value = tableEntry.getValue();
|
||||
ERAttributeDTO erAttributeDTO = new ERAttributeDTO(key, value.toString(), value instanceof Number ? "1" : "0");
|
||||
erAttributeDTOS.add(erAttributeDTO);
|
||||
}
|
||||
entityExtractionDTO.setAttributes(erAttributeDTOS);
|
||||
entities.add(entityExtractionDTO);
|
||||
}
|
||||
eredto.setEntities(entities);
|
||||
return eredto;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.supervision.pdfqaserver.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 实体抽取
|
||||
*/
|
||||
@Data
|
||||
public class EntityExtractionDTO {
|
||||
|
||||
private String id;
|
||||
|
||||
private String truncationId;
|
||||
|
||||
/**
|
||||
* 实体标签
|
||||
*/
|
||||
private String entity;
|
||||
|
||||
/**
|
||||
* 实体名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
private List<ERAttributeDTO> attributes;
|
||||
|
||||
public EntityExtractionDTO() {
|
||||
}
|
||||
|
||||
public EntityExtractionDTO(String truncationId, String entity, String name, List<ERAttributeDTO> attributes) {
|
||||
this.truncationId = truncationId;
|
||||
this.entity = entity;
|
||||
this.name = name;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.supervision.pdfqaserver.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 关系抽取
|
||||
*/
|
||||
@Data
|
||||
public class RelationExtractionDTO {
|
||||
|
||||
private String id;
|
||||
|
||||
private String truncationId;
|
||||
|
||||
/**
|
||||
* 头节点数据
|
||||
*/
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 头节点类型
|
||||
*/
|
||||
private String sourceType;
|
||||
|
||||
/**
|
||||
*关系
|
||||
*/
|
||||
private String relation;
|
||||
|
||||
/**
|
||||
* 尾节点数据
|
||||
*/
|
||||
private String target;
|
||||
|
||||
/**
|
||||
* 尾节点类型
|
||||
*/
|
||||
private String targetType;
|
||||
|
||||
private List<ERAttributeDTO> attributes;
|
||||
|
||||
public RelationExtractionDTO() {
|
||||
}
|
||||
|
||||
public RelationExtractionDTO(String truncationId,String source, String sourceType,String relation, String target,String targetType, List<ERAttributeDTO> attributes) {
|
||||
this.truncationId = truncationId;
|
||||
this.source = source;
|
||||
this.relation = relation;
|
||||
this.target = target;
|
||||
this.attributes = attributes;
|
||||
this.sourceType = sourceType;
|
||||
this.targetType = targetType;
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 文 件 名: CustomException
|
||||
* 版 权:
|
||||
* 描 述: <描述>
|
||||
* 修 改 人: RedName
|
||||
* 修改时间: 2022/8/5
|
||||
* 跟踪单号: <跟踪单号>
|
||||
* 修改单号: <修改单号>
|
||||
* 修改内容: <修改内容>
|
||||
*/
|
||||
package com.supervision.pdfqaserver.exception;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* <功能详细描述>
|
||||
* 自定义异常
|
||||
*
|
||||
* @author ljt
|
||||
* @version [版本号, 2022/8/5]
|
||||
* @see [相关类/方法]
|
||||
* @since [产品/模块版本]
|
||||
*/
|
||||
@Slf4j
|
||||
public class BusinessException extends RuntimeException {
|
||||
/**
|
||||
* 异常编码
|
||||
*/
|
||||
private final Integer code;
|
||||
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
private final String message;
|
||||
|
||||
public BusinessException(Throwable cause) {
|
||||
super(cause);
|
||||
this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
|
||||
this.message = null;
|
||||
|
||||
}
|
||||
|
||||
public BusinessException(Throwable cause, String message) {
|
||||
super(cause);
|
||||
this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
|
||||
this.message = message;
|
||||
|
||||
}
|
||||
|
||||
public BusinessException(String message) {
|
||||
this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public BusinessException(String message, Integer code) {
|
||||
this.message = message;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public BusinessException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
log.error(message, e);
|
||||
this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.supervision.pdfqaserver.mapper;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.ChineseEnglishWords;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【chinese_english_words(中英文对照字典)】的数据库操作Mapper
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
* @Entity com.supervision.pdfqaserver.domain.ChineseEnglishWords
|
||||
*/
|
||||
public interface ChineseEnglishWordsMapper extends BaseMapper<ChineseEnglishWords> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.supervision.pdfqaserver.mapper;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.DocumentTruncation;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【document_truncation(文档切分表)】的数据库操作Mapper
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
* @Entity com.supervision.pdfqaserver.domain.DocumentTruncation
|
||||
*/
|
||||
public interface DocumentTruncationMapper extends BaseMapper<DocumentTruncation> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.supervision.pdfqaserver.mapper;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.DomainMetadata;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【domain_metadata(领域元数据)】的数据库操作Mapper
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
* @Entity com.supervision.pdfqaserver.domain.DomainMetadata
|
||||
*/
|
||||
public interface DomainMetadataMapper extends BaseMapper<DomainMetadata> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.supervision.pdfqaserver.mapper;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.PdfAnalysisOutput;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【pdf_analysis_output】的数据库操作Mapper
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
* @Entity com.supervision.pdfqaserver.domain.PdfAnalysisOutput
|
||||
*/
|
||||
public interface PdfAnalysisOutputMapper extends BaseMapper<PdfAnalysisOutput> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.supervision.pdfqaserver.mapper;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.PdfInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【pdf_info(pdf信息)】的数据库操作Mapper
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
* @Entity com.supervision.pdfqaserver.domain.PdfInfo
|
||||
*/
|
||||
public interface PdfInfoMapper extends BaseMapper<PdfInfo> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.supervision.pdfqaserver.mapper;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.TruncationEntityExtraction;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【truncation_entity_extraction(片段实体抽取)】的数据库操作Mapper
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
* @Entity com.supervision.pdfqaserver.domain.TruncationEntityExtraction
|
||||
*/
|
||||
public interface TruncationEntityExtractionMapper extends BaseMapper<TruncationEntityExtraction> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.supervision.pdfqaserver.mapper;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.TruncationErAttribute;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【truncation_er_attribute(实体表)】的数据库操作Mapper
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
* @Entity com.supervision.pdfqaserver.domain.TruncationErAttribute
|
||||
*/
|
||||
public interface TruncationErAttributeMapper extends BaseMapper<TruncationErAttribute> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.supervision.pdfqaserver.mapper;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.TruncationRelationExtraction;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【truncation_relation_extraction(片段关系抽取)】的数据库操作Mapper
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
* @Entity com.supervision.pdfqaserver.domain.TruncationRelationExtraction
|
||||
*/
|
||||
public interface TruncationRelationExtractionMapper extends BaseMapper<TruncationRelationExtraction> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.ChineseEnglishWords;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【chinese_english_words(中英文对照字典)】的数据库操作Service
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
public interface ChineseEnglishWordsService extends IService<ChineseEnglishWords> {
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.dto.DocumentDTO;
|
||||
import com.supervision.pdfqaserver.dto.TruncateDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文档切分器
|
||||
*/
|
||||
public interface DocumentSlicer {
|
||||
|
||||
/**
|
||||
* 切分文档
|
||||
* @param documents 文档列表
|
||||
* @return
|
||||
*/
|
||||
List<TruncateDTO> slice(List<DocumentDTO> documents);
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.DocumentTruncation;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.supervision.pdfqaserver.dto.TruncateDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【document_truncation(文档切分表)】的数据库操作Service
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
public interface DocumentTruncationService extends IService<DocumentTruncation> {
|
||||
|
||||
|
||||
void batchSave(List<TruncateDTO> truncateDTOS);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.DomainMetadata;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【domain_metadata(领域元数据)】的数据库操作Service
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
public interface DomainMetadataService extends IService<DomainMetadata> {
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.dto.EREDTO;
|
||||
|
||||
/**
|
||||
* 知识图谱服务接口
|
||||
*/
|
||||
public interface KnowledgeGraphService {
|
||||
|
||||
|
||||
/**
|
||||
* 生成知识图谱
|
||||
* @param documentId 文档ID
|
||||
*/
|
||||
void generateGraph(String documentId);
|
||||
|
||||
void queryGraph(String databaseId, String query);
|
||||
|
||||
|
||||
void saveERE(EREDTO eredto, String truncationId);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.PdfAnalysisOutput;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【pdf_analysis_output】的数据库操作Service
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
public interface PdfAnalysisOutputService extends IService<PdfAnalysisOutput> {
|
||||
|
||||
List<PdfAnalysisOutput> queryByPdfId(String pdfId);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.PdfInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【pdf_info(pdf信息)】的数据库操作Service
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
public interface PdfInfoService extends IService<PdfInfo> {
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.dto.EREDTO;
|
||||
import com.supervision.pdfqaserver.dto.DocumentDTO;
|
||||
import com.supervision.pdfqaserver.dto.TruncateDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 三元组转换管道
|
||||
*/
|
||||
public interface TripleConversionPipeline {
|
||||
|
||||
/**
|
||||
* 切分文档
|
||||
* @param documents 文档列表
|
||||
* @return
|
||||
*/
|
||||
List<TruncateDTO> sliceDocuments(List<DocumentDTO> documents);
|
||||
|
||||
|
||||
/**
|
||||
* 实体关系抽取
|
||||
* @param truncateDTO 切分文档
|
||||
* @return
|
||||
*/
|
||||
EREDTO doEre(TruncateDTO truncateDTO);
|
||||
|
||||
/**
|
||||
* 合并实体关系抽取结果
|
||||
* @param eredtoList 实体关系抽取结果列表
|
||||
* @return
|
||||
*/
|
||||
List<EREDTO> mergeEreResults(List<EREDTO> eredtoList);
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.dto.EREDTO;
|
||||
|
||||
/**
|
||||
* 三元组转换为Cypher语句的执行器
|
||||
*/
|
||||
public interface TripleToCypherExecutor {
|
||||
|
||||
/**
|
||||
* 生成Cypher语句
|
||||
* @param eredto
|
||||
* @return
|
||||
*/
|
||||
String generateInsertCypher(EREDTO eredto);
|
||||
|
||||
|
||||
/**
|
||||
* 生成查询Cypher语句
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
String generateQueryCypher(String query);
|
||||
|
||||
/**
|
||||
* 执行Cypher语句
|
||||
* @param cypher
|
||||
* @return
|
||||
*/
|
||||
void executeCypher(String cypher);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.TruncationEntityExtraction;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【truncation_entity_extraction(片段实体抽取)】的数据库操作Service
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
public interface TruncationEntityExtractionService extends IService<TruncationEntityExtraction> {
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.TruncationErAttribute;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【truncation_er_attribute(实体表)】的数据库操作Service
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
public interface TruncationErAttributeService extends IService<TruncationErAttribute> {
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.domain.TruncationRelationExtraction;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【truncation_relation_extraction(片段关系抽取)】的数据库操作Service
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
public interface TruncationRelationExtractionService extends IService<TruncationRelationExtraction> {
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.supervision.pdfqaserver.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.supervision.pdfqaserver.domain.ChineseEnglishWords;
|
||||
import com.supervision.pdfqaserver.service.ChineseEnglishWordsService;
|
||||
import com.supervision.pdfqaserver.mapper.ChineseEnglishWordsMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【chinese_english_words(中英文对照字典)】的数据库操作Service实现
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
@Service
|
||||
public class ChineseEnglishWordsServiceImpl extends ServiceImpl<ChineseEnglishWordsMapper, ChineseEnglishWords>
|
||||
implements ChineseEnglishWordsService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.supervision.pdfqaserver.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.supervision.pdfqaserver.domain.DocumentTruncation;
|
||||
import com.supervision.pdfqaserver.dto.TruncateDTO;
|
||||
import com.supervision.pdfqaserver.service.DocumentTruncationService;
|
||||
import com.supervision.pdfqaserver.mapper.DocumentTruncationMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【document_truncation(文档切分表)】的数据库操作Service实现
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
@Service
|
||||
public class DocumentTruncationServiceImpl extends ServiceImpl<DocumentTruncationMapper, DocumentTruncation>
|
||||
implements DocumentTruncationService{
|
||||
|
||||
@Override
|
||||
public void batchSave(List<TruncateDTO> truncateDTOS) {
|
||||
if (CollUtil.isEmpty(truncateDTOS)){
|
||||
return;
|
||||
}
|
||||
truncateDTOS.stream().map(TruncateDTO::toDocumentTruncation).forEach(this::save);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.supervision.pdfqaserver.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.supervision.pdfqaserver.domain.DomainMetadata;
|
||||
import com.supervision.pdfqaserver.service.DomainMetadataService;
|
||||
import com.supervision.pdfqaserver.mapper.DomainMetadataMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【domain_metadata(领域元数据)】的数据库操作Service实现
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
@Service
|
||||
public class DomainMetadataServiceImpl extends ServiceImpl<DomainMetadataMapper, DomainMetadata>
|
||||
implements DomainMetadataService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,84 @@
|
||||
package com.supervision.pdfqaserver.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.supervision.pdfqaserver.dto.EREDTO;
|
||||
import com.supervision.pdfqaserver.domain.PdfAnalysisOutput;
|
||||
import com.supervision.pdfqaserver.dto.DocumentDTO;
|
||||
import com.supervision.pdfqaserver.dto.TruncateDTO;
|
||||
import com.supervision.pdfqaserver.service.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class KnowledgeGraphServiceImpl implements KnowledgeGraphService {
|
||||
|
||||
private final TripleConversionPipeline tripleConversionPipeline;
|
||||
|
||||
private final TripleToCypherExecutor tripleToCypherExecutor;
|
||||
|
||||
private final ChineseEnglishWordsService chineseEnglishWordsService;
|
||||
|
||||
private final DocumentTruncationService documentTruncationService;
|
||||
|
||||
private final DomainMetadataService domainMetadataService;
|
||||
|
||||
private final PdfAnalysisOutputService pdfAnalysisOutputService;
|
||||
|
||||
private final PdfInfoService pdfInfoService;
|
||||
|
||||
private final TruncationEntityExtractionService truncationEntityExtractionService;
|
||||
|
||||
private final TruncationRelationExtractionService relationExtractionService;
|
||||
|
||||
private final TruncationErAttributeService truncationErAttributeService;
|
||||
|
||||
@Override
|
||||
public void generateGraph(String documentId) {
|
||||
List<PdfAnalysisOutput> pdfAnalysisOutputs = pdfAnalysisOutputService.queryByPdfId(documentId);
|
||||
if (CollUtil.isEmpty(pdfAnalysisOutputs)) {
|
||||
log.info("没有找到pdfId为{}的pdf分析结果", documentId);
|
||||
return;
|
||||
}
|
||||
List<DocumentDTO> documentDTOList = pdfAnalysisOutputs.stream().map(DocumentDTO::new).toList();
|
||||
// 对文档进行切分
|
||||
List<TruncateDTO> truncateDTOS = tripleConversionPipeline.sliceDocuments(documentDTOList);
|
||||
// 保存分片信息
|
||||
documentTruncationService.batchSave(truncateDTOS);
|
||||
|
||||
// 对切分后的文档进行命名实体识别
|
||||
List<EREDTO> eredtoList = new ArrayList<>();
|
||||
for (TruncateDTO truncateDTO : truncateDTOS) {
|
||||
EREDTO eredto = tripleConversionPipeline.doEre(truncateDTO);
|
||||
// 保存实体关系抽取结果
|
||||
this.saveERE(eredto, truncateDTO.getId());
|
||||
}
|
||||
|
||||
// 合并实体关系抽取结果
|
||||
List<EREDTO> mergedList = tripleConversionPipeline.mergeEreResults(eredtoList);
|
||||
|
||||
for (EREDTO eredto : mergedList) {
|
||||
String insertCypher = tripleToCypherExecutor.generateInsertCypher(eredto);
|
||||
|
||||
tripleToCypherExecutor.executeCypher(insertCypher);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queryGraph(String databaseId, String query) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveERE(EREDTO eredto, String truncationId) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.supervision.pdfqaserver.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.supervision.pdfqaserver.domain.PdfAnalysisOutput;
|
||||
import com.supervision.pdfqaserver.service.PdfAnalysisOutputService;
|
||||
import com.supervision.pdfqaserver.mapper.PdfAnalysisOutputMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【pdf_analysis_output】的数据库操作Service实现
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
@Service
|
||||
public class PdfAnalysisOutputServiceImpl extends ServiceImpl<PdfAnalysisOutputMapper, PdfAnalysisOutput>
|
||||
implements PdfAnalysisOutputService{
|
||||
|
||||
@Override
|
||||
public List<PdfAnalysisOutput> queryByPdfId(String pdfId) {
|
||||
Assert.notEmpty(pdfId, "pdfId不能为空");
|
||||
|
||||
return super.lambdaQuery().eq(PdfAnalysisOutput::getPdfId, pdfId).list();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.supervision.pdfqaserver.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.supervision.pdfqaserver.domain.PdfInfo;
|
||||
import com.supervision.pdfqaserver.service.PdfInfoService;
|
||||
import com.supervision.pdfqaserver.mapper.PdfInfoMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【pdf_info(pdf信息)】的数据库操作Service实现
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
@Service
|
||||
public class PdfInfoServiceImpl extends ServiceImpl<PdfInfoMapper, PdfInfo>
|
||||
implements PdfInfoService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,105 @@
|
||||
package com.supervision.pdfqaserver.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.supervision.pdfqaserver.cache.PromptCache;
|
||||
import com.supervision.pdfqaserver.dto.*;
|
||||
import com.supervision.pdfqaserver.service.TripleConversionPipeline;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.ai.ollama.OllamaChatModel;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TripleConversionPipelineImpl implements TripleConversionPipeline {
|
||||
|
||||
private final OllamaChatModel ollamaChatModel;
|
||||
|
||||
@Override
|
||||
public List<TruncateDTO> sliceDocuments(List<DocumentDTO> documents) {
|
||||
// 对pdfAnalysisOutputs进行排序
|
||||
List<DocumentDTO> documentDTOList = documents.stream().sorted(
|
||||
// 先对pageNo进行排序再对layoutOrder进行排序
|
||||
(o1, o2) -> {
|
||||
if (o1.getPageNo().equals(o2.getPageNo())) {
|
||||
return Integer.compare(o1.getLayoutOrder(), o2.getLayoutOrder());
|
||||
}
|
||||
return Integer.compare(o1.getPageNo(), o2.getPageNo());
|
||||
}
|
||||
).toList();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EREDTO doEre(TruncateDTO truncateDTO) {
|
||||
|
||||
if (StrUtil.equals(truncateDTO.getLayoutType(),"0")){
|
||||
|
||||
EREDTO eredto = doTextEre(truncateDTO);
|
||||
return eredto;
|
||||
}
|
||||
|
||||
if (StrUtil.equals(truncateDTO.getLayoutType(),"1")){
|
||||
EREDTO eredto = doTableEre(truncateDTO);
|
||||
return eredto;
|
||||
}
|
||||
log.info("doEre:错误的布局类型: {}", truncateDTO.getLayoutType());
|
||||
return null;
|
||||
}
|
||||
|
||||
private EREDTO doTextEre(TruncateDTO truncateDTO) {
|
||||
String prompt = PromptCache.promptMap.get(PromptCache.DOERE_TEXT);
|
||||
String formatted = String.format(prompt, truncateDTO.getContent());
|
||||
String response = ollamaChatModel.call(formatted);
|
||||
// todo:暂时不去处理异常返回
|
||||
|
||||
return EREDTO.fromTextJson(response, truncateDTO.getId());
|
||||
}
|
||||
|
||||
private EREDTO doTableEre(TruncateDTO truncateDTO) {
|
||||
String prompt = PromptCache.promptMap.get(PromptCache.DOERE_TABLE);
|
||||
String formatted = String.format(prompt, truncateDTO.getContent());
|
||||
String response = ollamaChatModel.call(formatted);
|
||||
// todo:暂时不去处理异常返回
|
||||
|
||||
return EREDTO.fromTableJson(response, truncateDTO.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并实体关系抽取结果 主要是对实体和关系中的属性进行合并
|
||||
* @param eredtoList 实体关系抽取结果列表
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<EREDTO> mergeEreResults(List<EREDTO> eredtoList) {
|
||||
List<EREDTO> merged = new ArrayList<>();
|
||||
if (CollUtil.isEmpty(eredtoList)){
|
||||
return merged;
|
||||
}
|
||||
for (EREDTO eredto : eredtoList) {
|
||||
List<EntityExtractionDTO> entities = eredto.getEntities();
|
||||
if (CollUtil.isNotEmpty(entities)){
|
||||
for (EntityExtractionDTO entity : entities) {
|
||||
String e = entity.getEntity();
|
||||
String name = entity.getName();
|
||||
// entity.getEntity() 和 entity.getName() 完全相等看作是同一个数据
|
||||
}
|
||||
}
|
||||
List<RelationExtractionDTO> relations = eredto.getRelations();
|
||||
if (CollUtil.isNotEmpty(relations)){
|
||||
for (RelationExtractionDTO relation : relations) {
|
||||
String source = relation.getSource();
|
||||
String target = relation.getTarget();
|
||||
String re = relation.getRelation();
|
||||
// source和target,re完全相等看作是同一个数据
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.supervision.pdfqaserver.service.impl;
|
||||
|
||||
import com.supervision.pdfqaserver.dto.EREDTO;
|
||||
import com.supervision.pdfqaserver.service.TripleToCypherExecutor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.ai.ollama.OllamaChatModel;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
|
||||
|
||||
private final OllamaChatModel ollamaChatModel;
|
||||
@Override
|
||||
public String generateInsertCypher(EREDTO eredto) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateQueryCypher(String query) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeCypher(String cypher) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.supervision.pdfqaserver.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.supervision.pdfqaserver.domain.TruncationEntityExtraction;
|
||||
import com.supervision.pdfqaserver.service.TruncationEntityExtractionService;
|
||||
import com.supervision.pdfqaserver.mapper.TruncationEntityExtractionMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【truncation_entity_extraction(片段实体抽取)】的数据库操作Service实现
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
@Service
|
||||
public class TruncationEntityExtractionServiceImpl extends ServiceImpl<TruncationEntityExtractionMapper, TruncationEntityExtraction>
|
||||
implements TruncationEntityExtractionService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.supervision.pdfqaserver.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.supervision.pdfqaserver.domain.TruncationErAttribute;
|
||||
import com.supervision.pdfqaserver.service.TruncationErAttributeService;
|
||||
import com.supervision.pdfqaserver.mapper.TruncationErAttributeMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【truncation_er_attribute(实体表)】的数据库操作Service实现
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
@Service
|
||||
public class TruncationErAttributeServiceImpl extends ServiceImpl<TruncationErAttributeMapper, TruncationErAttribute>
|
||||
implements TruncationErAttributeService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.supervision.pdfqaserver.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.supervision.pdfqaserver.domain.TruncationRelationExtraction;
|
||||
import com.supervision.pdfqaserver.service.TruncationRelationExtractionService;
|
||||
import com.supervision.pdfqaserver.mapper.TruncationRelationExtractionMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【truncation_relation_extraction(片段关系抽取)】的数据库操作Service实现
|
||||
* @createDate 2025-04-27 11:45:24
|
||||
*/
|
||||
@Service
|
||||
public class TruncationRelationExtractionServiceImpl extends ServiceImpl<TruncationRelationExtractionMapper, TruncationRelationExtraction>
|
||||
implements TruncationRelationExtractionService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.supervision.pdfqaserver.mapper.ChineseEnglishWordsMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.supervision.pdfqaserver.domain.ChineseEnglishWords">
|
||||
<id property="chineseWord" column="chinese_word" jdbcType="VARCHAR"/>
|
||||
<result property="englishWord" column="english_word" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
chinese_word,english_word,create_time,
|
||||
update_time
|
||||
</sql>
|
||||
</mapper>
|
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.supervision.pdfqaserver.mapper.DocumentTruncationMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.supervision.pdfqaserver.domain.DocumentTruncation">
|
||||
<id property="id" column="id" jdbcType="VARCHAR"/>
|
||||
<result property="documentId" column="document_id" jdbcType="INTEGER"/>
|
||||
<result property="sectionId" column="section_id" jdbcType="VARCHAR"/>
|
||||
<result property="layoutType" column="layout_type" jdbcType="VARCHAR"/>
|
||||
<result property="title" column="title" jdbcType="VARCHAR"/>
|
||||
<result property="content" column="content" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,document_id,section_id,title,
|
||||
layout_type,content,create_time,
|
||||
update_time
|
||||
</sql>
|
||||
</mapper>
|
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.supervision.pdfqaserver.mapper.DomainMetadataMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.supervision.pdfqaserver.domain.DomainMetadata">
|
||||
<id property="id" column="id" jdbcType="VARCHAR"/>
|
||||
<result property="domainType" column="domain_type" jdbcType="VARCHAR"/>
|
||||
<result property="sourceType" column="source_type" jdbcType="VARCHAR"/>
|
||||
<result property="relation" column="relation" jdbcType="VARCHAR"/>
|
||||
<result property="targetType" column="target_type" jdbcType="VARCHAR"/>
|
||||
<result property="generationType" column="generation_type" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,domain_type,source_type,
|
||||
relation,target_type,generation_type,
|
||||
create_time,update_time
|
||||
</sql>
|
||||
</mapper>
|
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.supervision.pdfqaserver.mapper.PdfAnalysisOutputMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.supervision.pdfqaserver.domain.PdfAnalysisOutput">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="layoutType" column="layout_type" jdbcType="INTEGER"/>
|
||||
<result property="content" column="content" jdbcType="VARCHAR"/>
|
||||
<result property="pageNo" column="page_no" jdbcType="INTEGER"/>
|
||||
<result property="pdfId" column="pdf_id" jdbcType="INTEGER"/>
|
||||
<result property="tableTitle" column="table_title" jdbcType="VARCHAR"/>
|
||||
<result property="order" column="order" jdbcType="INTEGER"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,layout_type,content,
|
||||
page_no,pdf_id,table_title,
|
||||
order,create_time
|
||||
</sql>
|
||||
</mapper>
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.supervision.pdfqaserver.mapper.PdfInfoMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.supervision.pdfqaserver.domain.PdfInfo">
|
||||
<result property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="path" column="path" jdbcType="VARCHAR"/>
|
||||
<result property="filename" column="filename" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,path,filename,
|
||||
create_time
|
||||
</sql>
|
||||
</mapper>
|
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.supervision.pdfqaserver.mapper.TruncationEntityExtractionMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.supervision.pdfqaserver.domain.TruncationEntityExtraction">
|
||||
<id property="id" column="id" jdbcType="VARCHAR"/>
|
||||
<result property="truncationId" column="truncation_id" jdbcType="VARCHAR"/>
|
||||
<result property="entity" column="entity" jdbcType="VARCHAR"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,truncation_id,entity,
|
||||
name,create_time,update_time
|
||||
</sql>
|
||||
</mapper>
|
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.supervision.pdfqaserver.mapper.TruncationErAttributeMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.supervision.pdfqaserver.domain.TruncationErAttribute">
|
||||
<id property="id" column="id" jdbcType="VARCHAR"/>
|
||||
<result property="terId" column="ter_id" jdbcType="VARCHAR"/>
|
||||
<result property="type" column="type" jdbcType="VARCHAR"/>
|
||||
<result property="attribute" column="attribute" jdbcType="VARCHAR"/>
|
||||
<result property="value" column="value" jdbcType="VARCHAR"/>
|
||||
<result property="dataType" column="data_type" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,ter_id,type,
|
||||
attribute,value,data_type,
|
||||
create_time,update_time
|
||||
</sql>
|
||||
</mapper>
|
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.supervision.pdfqaserver.mapper.TruncationRelationExtractionMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.supervision.pdfqaserver.domain.TruncationRelationExtraction">
|
||||
<id property="id" column="id" jdbcType="VARCHAR"/>
|
||||
<result property="truncationId" column="truncation_id" jdbcType="VARCHAR"/>
|
||||
<result property="source" column="source" jdbcType="VARCHAR"/>
|
||||
<result property="sourceType" column="source_type" jdbcType="VARCHAR"/>
|
||||
<result property="target" column="target" jdbcType="VARCHAR"/>
|
||||
<result property="targetType" column="target_type" jdbcType="VARCHAR"/>
|
||||
<result property="relation" column="relation" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,truncation_id,source,
|
||||
source_type,target,target_type,
|
||||
relation,create_time,update_time
|
||||
</sql>
|
||||
</mapper>
|
Loading…
Reference in New Issue