初始化代码

master
xueqingkun 9 hours ago
parent b8418fc60c
commit b9c957a74a

@ -23,15 +23,32 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-ollama</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-3-starter</artifactId>
<version>1.2.21</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.7</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.5</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
@ -48,6 +65,21 @@
<artifactId>hutool-all</artifactId>
<version>5.8.26</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83_noneautotype</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.3</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
@ -61,33 +93,4 @@
</dependencies>
</dependencyManagement>
<build>
<plugins>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>-->
</plugins>
</build>
</project>

@ -1,9 +1,10 @@
package com.supervision.pdfqaserver;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@MapperScan(basePackages = {"com.supervision.pdfqaserver.mapper"})
@SpringBootApplication
public class PdfQaServerApplication {

@ -0,0 +1,185 @@
package com.supervision.pdfqaserver.cache;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
public class PromptCache {
public static final String DOERE_TEXT = "DOERE_TEXT";
public static final String DOERE_TABLE = "DOERE_TABLE";
public static final Map<String, String> promptMap = new HashMap<>();
static {
init();
}
private static void init(){
promptMap.put(DOERE_TEXT, DOERE_TEXT_PROMPT);
promptMap.put(DOERE_TABLE, DOERE_TABLE_PROMPT);
}
private static final String DOERE_TEXT_PROMPT = """
JSON
1. ****
-
-
-
2. ****
-
-
-
3. ****
- (, , )
****
- 使JSON Schema
{
"nodes": [
{
"name": "节点名称",
"type": "节点类型",
"attributes": {
"属性名1": "属性值1",
"属性名2": "属性值2"
}
}
],
"relations": [
{
"source": "头节点名称",
"target": "尾节点名称",
"type": "关系类型",
"attributes": {
"关系属性名1": "关系属性值1"
}
}
],
"typed_triplets": [
["头节点类型", "关系类型", "尾节点类型"]
]
}
****
1. "科学家"/"发明"/"研究所"
2.
3. "特斯拉""埃隆·马斯克的公司"
****
"爱因斯坦在1905年发表了狭义相对论论文这篇革命性理论后来被普林斯顿高等研究院深入研究"
****
{
"nodes": [
{
"name": "爱因斯坦",
"type": "物理学家",
"attributes": {
"领域": "理论物理"
}
},
{
"name": "狭义相对论",
"type": "科学理论",
"attributes": {
"发表年份": 1905,
"重要性": "革命性"
}
},
{
"name": "普林斯顿高等研究院",
"type": "科研机构",
"attributes": {
"研究领域": "理论科学"
}
}
],
"relations": [
{
"source": "爱因斯坦",
"target": "狭义相对论",
"type": "发表",
"attributes": {
"时间": 1905
}
},
{
"source": "普林斯顿高等研究院",
"target": "狭义相对论",
"type": "研究",
"attributes": {
"强度描述": "深入"
}
}
],
"typed_triplets": [
["物理学家", "发表", "科学理论"],
["科研机构", "研究", "科学理论"]
]
}
{}
""";
private static final String DOERE_TABLE_PROMPT = """
****
1.
2.
3.
4.
****
```json
{
"table_data": [
{
"[第一列表头]": "[第一列值]",
"[第二列表头]": "[第二列值]",
"[第三列表头]": "[第三列值]"
},
// 后续行...
]
}
```
****
| | | |
| --- | --- | --- |
| 1 | 310,844,201.27 | 337,641,834.84 |
| 12 | 52,374,904.35 | 15,041,750.36 |
****
{
"table_data": [
{
"账龄": "1年以内",
"期末余额": "310,844,201.27",
"年初余额": "337,641,834.84"
},
{
"账龄": "1至2年",
"期末余额": "52,374,904.35",
"年初余额": "15,041,750.36"
}
]
}
{}
""";
}

@ -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,55 @@
package com.supervision.pdfqaserver.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
*
* @author qimaoyu
* @create 2019-07-14 10:22
*/
@NoArgsConstructor
@AllArgsConstructor
public enum ResultStatusEnum {
AUTHENTICATION_FAILED(320, "token失效请重新登录"),
NO_ACCESS_TO_THIS_INTERFACE(320, "无权访问此接口!"),
FAILED_TO_GENERATE_TOKEN(321, "生成token失败"),
ACCOUNT_PASSWORD_INCORRECT(322, "账号或密码错误!"),
ACCOUNT_NOT_CREATE(323, "账号未创建!"),
HAS_BEEN_PULLED_BLACK(324, "已被删除或禁用,无法登录!"),
USERNAME_MAIL_IS_EXIST(341, "登录名称已经被注册!"),
USERNAME_IS_BLANK(342, "登录名称为空!"),
VERIFICATION_CODE_EXPIRED(350,"验证码已过期,请重新获取。"),
VERIFICATION_CODE_FAILURE(351,"验证码输入错误。"),
OPERATE_FAIL(360,"修改毕业生信息失败。"),
DATA_IS_EMPTY(370,"查询到的结果为空"),
SYSTEM_ABNORMAL(500, "系统繁忙,请稍后重试!"),
UPLOAD_EXCEPTION(501, "文件上传异常!"),
EXPORT_EXCEPTION(502, "文件导出异常!"),
INCORRECT_FILE_FORMAT(503, "文件格式不正确!"),
PARAMETER_CANNOT_BE_EMPTY(504, "参数不能为空,操作失败!"),
NO_TEMP_UPLOADFILEPATH(505,"未配置文件上传临时存储路径"),
USER_DOES_NOT_EXIST(507, "用户不存在,操作失败!"),
ILLEGAL_ARGUMENT(508, "参数校验失败!"),
RUNTIME_EXCEPTION(509, "程序运行异常!"),
EXCEED_FILE_SIZE(510, "文件大小超出限制!"),
IMPORT_COMPANY_FORMAT_ERROR(521,"Excel表格格式错误"),
IMPORT_COMPANY_FAIL(522,"部分数据导入失败"),
INSERT_FAIL(600,"新增失败"),
DuplicateKeyException(601,"该条信息已经存在,请勿重复添加"),
UPDATE_FAIL(700,"更新失败"),
DELETE_FAIL(800,"删除失败"),
YEAR_IS_CLOSE(1001,"该年度暂未开启");
@Getter
@Setter
private int code;
@Getter
@Setter
private String message;
}

@ -23,6 +23,11 @@ public class ChatController {
private final OllamaChatModel ollamaChatModel;
/**
* 使
* @param message
* @return
*/
@PostMapping("/chat")
public R<String> pageList(@RequestBody Map<String,String> message) {
List<Message> messages = new ArrayList<>();

@ -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_infoid)
*/
private Integer documentId;
/**
* id pdf_analysis_outputid
*/
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,60 @@
package com.supervision.pdfqaserver.domain;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
/**
*
* @TableName domain_metadata
*/
@TableName(value ="domain_metadata")
@Data
public class DomainMetadata implements Serializable {
/**
*
*/
@TableId
private String id;
/**
*
*/
private String domainType;
/**
*
*/
private String sourceType;
/**
*
*/
private String relation;
/**
*
*/
private String targetType;
/**
* 0=1=
*/
private String generationType;
/**
*
*/
@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,60 @@
package com.supervision.pdfqaserver.domain;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
/**
*
* @TableName pdf_analysis_output
*/
@TableName(value ="pdf_analysis_output")
@Data
public class PdfAnalysisOutput implements Serializable {
/**
*
*/
@TableId
private Integer id;
/**
* 0- 1-
*/
private Integer layoutType;
/**
* pdf
*/
private String content;
/**
* pdf
*/
private Integer pageNo;
/**
* pdf_info
*/
private Integer pdfId;
/**
*
*/
private String tableTitle;
/**
* pdf
*/
private Integer order;
/**
*
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
@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_truncationid
*/
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,61 @@
package com.supervision.pdfqaserver.domain;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
/**
*
* @TableName truncation_er_attribute
*/
@TableName(value ="truncation_er_attribute")
@Data
public class TruncationErAttribute implements Serializable {
/**
*
*/
@TableId
private String id;
/**
* truncation_entity_extractionidtruncation_relation_extractionid
*/
private String terId;
/**
* 0terIdid 1terIdid
*/
private String type;
/**
*
*/
private String attribute;
/**
*
*/
private String value;
/**
* 0 1
*/
private String dataType;
/**
*
*/
@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;
}

@ -1,5 +1,6 @@
package com.supervision.pdfqaserver.dto;
import com.supervision.pdfqaserver.domain.PdfAnalysisOutput;
import lombok.Data;
/**
@ -7,19 +8,29 @@ import lombok.Data;
*/
@Data
public class DocumentDTO {
/**
* id
*/
private String id;
private Integer documentId;
private Integer sectionId;
private Integer pageNo;
/**
*
* 0 1
*/
private Integer index;
private String layoutType;
/**
* 0 1
* pdf
*/
private String type;
private Integer layoutOrder;
private String title;
/**
*
@ -32,10 +43,21 @@ public class DocumentDTO {
private Integer pageNum;
/**
*
*/
private String fileName;
public DocumentDTO() {
}
public DocumentDTO(PdfAnalysisOutput pdfAnalysisOutput) {
this.sectionId = pdfAnalysisOutput.getId();
this.documentId = pdfAnalysisOutput.getPdfId();
if (null != pdfAnalysisOutput.getLayoutType()) {
this.layoutType = pdfAnalysisOutput.getLayoutType().toString();
}
this.pageNo = pdfAnalysisOutput.getPageNo();
this.title = pdfAnalysisOutput.getTableTitle();
this.content = pdfAnalysisOutput.getContent();
this.layoutOrder = pdfAnalysisOutput.getOrder();
}
}

@ -0,0 +1,35 @@
package com.supervision.pdfqaserver.dto;
import lombok.Data;
@Data
public class DomainMetadataDTO {
private String id;
/**
*
*/
private String domainType;
/**
*
*/
private String sourceType;
/**
*
*/
private String relation;
/**
*
*/
private String targetType;
/**
* 0=1=
*/
private String generationType;
}

@ -0,0 +1,46 @@
package com.supervision.pdfqaserver.dto;
import lombok.Data;
/**
*
*/
@Data
public class ERAttributeDTO {
private String id;
/**
* truncation_entity_extractionidtruncation_relation_extractionid
*/
private String terId;
/**
* 0terIdid 1terIdid
*/
private String type;
/**
*
*/
private String attribute;
/**
*
*/
private String value;
/**
* 0 1
*/
private String dataType;
public ERAttributeDTO() {
}
public ERAttributeDTO(String attribute, String value, String dataType) {
this.attribute = attribute;
this.value = value;
this.dataType = dataType;
}
}

@ -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;
}
}

@ -1,5 +1,6 @@
package com.supervision.pdfqaserver.dto;
import com.supervision.pdfqaserver.domain.DocumentTruncation;
import lombok.Data;
/**
@ -14,19 +15,43 @@ public class TruncateDTO {
private String id;
/**
* 0 1
* 0- 1-
*/
private String type;
private String layoutType;
/**
*
* id(pdf_infoid)
*/
private String content;
private Integer documentId;
/**
* id pdf_analysis_outputid
*/
private String sectionId;
/**
*
*/
private String title;
/**
*
*/
private String content;
public DocumentTruncation toDocumentTruncation() {
DocumentTruncation truncation = new DocumentTruncation();
truncation.setDocumentId(this.documentId);
truncation.setSectionId(this.sectionId);
truncation.setLayoutType(this.layoutType);
truncation.setTitle(this.title);
truncation.setContent(this.content);
return truncation;
}
}

@ -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_outputMapper
* @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_outputService
* @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_outputService
* @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{
}

@ -1,6 +1,16 @@
spring:
application:
name: pdf-qa-server
datasource:
druid:
url: jdbc:postgresql://192.168.10.137:54321/pdf-qa
username: postgres
password: 123456
driver-class-name: org.postgresql.Driver
servlet:
multipart:
max-file-size: 10MB
max-request-size: 100MB
ai:
ollama:
baseUrl: http://192.168.10.70:11434

@ -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…
Cancel
Save