|
|
|
@ -0,0 +1,750 @@
|
|
|
|
|
package com.supervision.police.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
|
|
|
|
|
import com.supervision.common.domain.R;
|
|
|
|
|
import com.supervision.common.utils.StringUtils;
|
|
|
|
|
import com.supervision.constant.PromptsEnum;
|
|
|
|
|
import com.supervision.police.domain.*;
|
|
|
|
|
import com.supervision.police.dto.LongTextSingleSentenceSummaryDto;
|
|
|
|
|
import com.supervision.police.dto.PieceSentenceIdDto;
|
|
|
|
|
import com.supervision.police.service.*;
|
|
|
|
|
import com.supervision.thread.*;
|
|
|
|
|
import com.supervision.utils.UserUtil;
|
|
|
|
|
import lombok.Data;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.ai.chat.ChatResponse;
|
|
|
|
|
import org.springframework.ai.chat.messages.UserMessage;
|
|
|
|
|
import org.springframework.ai.chat.prompt.Prompt;
|
|
|
|
|
import org.springframework.ai.ollama.OllamaChatClient;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.StopWatch;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author:longbao
|
|
|
|
|
* @Date:2024/12/10 10:22
|
|
|
|
|
* @Description: QA长文本
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
public class LongTextServiceImpl implements LongTextService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String HEAD_ENTITY_TYPE_ACTOR = "行为人";
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private NoteRecordService noteRecordService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private NoteRecordSplitService noteRecordSplitService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private NoteRecordSplitSentenceService noteRecordSplitSentenceService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private OllamaChatClient chatClient;
|
|
|
|
|
@Autowired
|
|
|
|
|
private NoteRecordSplitPieceSentenceService noteRecordSplitPieceSentenceService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ModelPieceRecordTypeService modelPieceRecordTypeService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private NotePiecePromptTypeRelService notePiecePromptTypeRelService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private NotePiecePromptService notePiecePromptService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private CasePersonService casePersonService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private PieceTripleInfoService pieceTripleInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 问答对中答的长文本三元组提取根据笔录id
|
|
|
|
|
*
|
|
|
|
|
* @param noteRecordId 笔录id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class)
|
|
|
|
|
public R<Object> qaAnswerLongTextTripletExtractionByNoteRecordId(String noteRecordId) {
|
|
|
|
|
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction]开始");
|
|
|
|
|
|
|
|
|
|
StopWatch stopWatch = new StopWatch();
|
|
|
|
|
stopWatch.start();
|
|
|
|
|
|
|
|
|
|
// 校验参数
|
|
|
|
|
if (StringUtils.isNull(noteRecordId)) {
|
|
|
|
|
stopWatch.stop();
|
|
|
|
|
log.error("[QaAnswerLongTextTripletExtraction]笔录id不存在{}", noteRecordId);
|
|
|
|
|
log.warn("[QaAnswerLongTextTripletExtraction]主线程程序总耗时:{}", stopWatch.getTotalTimeSeconds());
|
|
|
|
|
return R.fail("笔录id不可为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询笔录是否存在
|
|
|
|
|
NoteRecord noteRecord = noteRecordService
|
|
|
|
|
.lambdaQuery()
|
|
|
|
|
.select(NoteRecord::getId)
|
|
|
|
|
.eq(NoteRecord::getId, noteRecordId)
|
|
|
|
|
.one();
|
|
|
|
|
if (null == noteRecord) {
|
|
|
|
|
stopWatch.stop();
|
|
|
|
|
log.error("[QaAnswerLongTextTripletExtraction]笔录不存在{}", noteRecordId);
|
|
|
|
|
log.warn("[QaAnswerLongTextTripletExtraction]主线程程序总耗时:{}", stopWatch.getTotalTimeSeconds());
|
|
|
|
|
return R.fail("该笔录不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 笔录是否已拆分QA
|
|
|
|
|
List<NoteRecordSplit> noteRecordSplits = noteRecordSplitService
|
|
|
|
|
.lambdaQuery()
|
|
|
|
|
.select(NoteRecordSplit::getId, NoteRecordSplit::getAnswer)
|
|
|
|
|
.eq(NoteRecordSplit::getNoteRecordId, noteRecordId)
|
|
|
|
|
.list();
|
|
|
|
|
if (null == noteRecordSplits || noteRecordSplits.isEmpty()) {
|
|
|
|
|
stopWatch.stop();
|
|
|
|
|
log.error("[QaAnswerLongTextTripletExtraction]笔录未拆分{}", noteRecordId);
|
|
|
|
|
log.warn("[QaAnswerLongTextTripletExtraction]主线程程序总耗时:{}", stopWatch.getTotalTimeSeconds());
|
|
|
|
|
return R.fail("该笔录未拆分QA对");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
R<Object> threadPoolExecutorCheck = singlePointCheck();
|
|
|
|
|
if (null != threadPoolExecutorCheck) {
|
|
|
|
|
stopWatch.stop();
|
|
|
|
|
return threadPoolExecutorCheck;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取笔录片段中回答中的长文本
|
|
|
|
|
List<NoteRecordSplitSentence> noteRecordSplitList = matcherLongText(noteRecordSplits);
|
|
|
|
|
if (noteRecordSplitList.isEmpty()) {
|
|
|
|
|
stopWatch.stop();
|
|
|
|
|
log.error("[QaAnswerLongTextTripletExtraction]笔录无长文本{}", noteRecordId);
|
|
|
|
|
log.warn("[QaAnswerLongTextTripletExtraction]主线程程序总耗时:{}", stopWatch.getTotalTimeSeconds());
|
|
|
|
|
return R.fail("该笔录QA对未查询到长文本");
|
|
|
|
|
}
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction]校验通过");
|
|
|
|
|
|
|
|
|
|
// 保存长文本单句
|
|
|
|
|
noteRecordSplitSentenceService.saveBatch(noteRecordSplitList);
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction]保存长文本单句成功");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 长文本单句总结
|
|
|
|
|
List<String> noteRecordSplitAnswerList = new ArrayList<>();
|
|
|
|
|
for (NoteRecordSplitSentence noteRecordSplitSentence : noteRecordSplitList) {
|
|
|
|
|
Long noteRecordSplitSentenceId = noteRecordSplitSentence.getId();
|
|
|
|
|
String answer = noteRecordSplitSentence.getAnswer();
|
|
|
|
|
noteRecordSplitAnswerList.add(noteRecordSplitSentenceId + "、" + answer);
|
|
|
|
|
}
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction]长文本单句总结开始");
|
|
|
|
|
List<NoteRecordSplitSentence> noteRecordSplitSentences = chatAiLongTextSingleSentenceSummary(PromptsEnum.LONG_TEXT_SINGLE_SENTENCE_SUMMARY, noteRecordSplitAnswerList);
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction]长文本单句总结结束");
|
|
|
|
|
// 更新长文本单句
|
|
|
|
|
noteRecordSplitSentenceService.updateBatchById(noteRecordSplitSentences);
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction]更新长文本单句成功");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取answer片段对应的单句集合
|
|
|
|
|
List<Long> noteRecordSplitSentenceIdList = noteRecordSplitList
|
|
|
|
|
.stream()
|
|
|
|
|
.map(NoteRecordSplitSentence::getId)
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
List<LongTextSingleSentenceSummaryDto> longTextSingleSentenceSummaryDtoList = new ArrayList<>();
|
|
|
|
|
List<NoteRecordSplitSentence> splitSentences = noteRecordSplitSentenceService
|
|
|
|
|
.lambdaQuery()
|
|
|
|
|
.select(NoteRecordSplitSentence::getRecordSplitId)
|
|
|
|
|
.in(NoteRecordSplitSentence::getId, noteRecordSplitSentenceIdList)
|
|
|
|
|
.groupBy(NoteRecordSplitSentence::getRecordSplitId)
|
|
|
|
|
.list();
|
|
|
|
|
|
|
|
|
|
// 遍历长文本单句
|
|
|
|
|
for (NoteRecordSplitSentence noteRecordSplit : splitSentences) {
|
|
|
|
|
|
|
|
|
|
String noteRecordSplitId = noteRecordSplit.getRecordSplitId();
|
|
|
|
|
List<NoteRecordSplitSentence> recordSplitSentenceList = noteRecordSplitSentenceService
|
|
|
|
|
.lambdaQuery()
|
|
|
|
|
.eq(NoteRecordSplitSentence::getRecordSplitId, noteRecordSplitId)
|
|
|
|
|
.in(NoteRecordSplitSentence::getId, noteRecordSplitSentenceIdList)
|
|
|
|
|
.orderByAsc(NoteRecordSplitSentence::getId)
|
|
|
|
|
.list();
|
|
|
|
|
|
|
|
|
|
LongTextSingleSentenceSummaryDto longTextSingleSentenceSummaryDto = new LongTextSingleSentenceSummaryDto();
|
|
|
|
|
longTextSingleSentenceSummaryDto.setNoteRecordSplitId(noteRecordSplitId);
|
|
|
|
|
longTextSingleSentenceSummaryDto.setNoteRecordSplitSentences(recordSplitSentenceList);
|
|
|
|
|
longTextSingleSentenceSummaryDtoList.add(longTextSingleSentenceSummaryDto);
|
|
|
|
|
}
|
|
|
|
|
if (longTextSingleSentenceSummaryDtoList.isEmpty()) {
|
|
|
|
|
log.warn("[QaAnswerLongTextTripletExtraction]当前回答下的单句集合不可为空");
|
|
|
|
|
return R.fail("当前回答下的长文本单句集合为空");
|
|
|
|
|
}
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction]当前回答下的单句集合查询成功");
|
|
|
|
|
try {
|
|
|
|
|
// 遍历单句集合-同语义归纳
|
|
|
|
|
List<Future<Map<String, Object>>> futureList = new ArrayList<>();
|
|
|
|
|
for (LongTextSingleSentenceSummaryDto longTextSingleSentenceSummaryDto : longTextSingleSentenceSummaryDtoList) {
|
|
|
|
|
LongTextTask longTextTask = new LongTextTask(chatClient, longTextSingleSentenceSummaryDto, pieceSentenceSave());
|
|
|
|
|
Future<Map<String, Object>> submit = LongtextThreadPool.executorService.submit(longTextTask);
|
|
|
|
|
futureList.add(submit);
|
|
|
|
|
}
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction]:同语义归纳任务成功提交{}个任务....", futureList.size());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("[QaAnswerLongTextTripletExtraction]未知异常:", e);
|
|
|
|
|
return R.fail("长文本接口未知异常");
|
|
|
|
|
} finally {
|
|
|
|
|
stopWatch.stop();
|
|
|
|
|
log.warn("[QaAnswerLongTextTripletExtraction]主线程程序总耗时:{}", stopWatch.getTotalTimeSeconds());
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据类型查询提示词
|
|
|
|
|
*
|
|
|
|
|
* @param noteRecordSplitPieceSentence 同语义句
|
|
|
|
|
* @return person-案件信息 notePromptList-提示词
|
|
|
|
|
*/
|
|
|
|
|
private Map<String, Object> queryPromptByType(NoteRecordSplitPieceSentence noteRecordSplitPieceSentence) {
|
|
|
|
|
log.info("longTextExtractTripleInfo:同语义句类型查询开始");
|
|
|
|
|
|
|
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
// 判断同语义类型是否存在
|
|
|
|
|
String pieceSentenceId = noteRecordSplitPieceSentence.getId();
|
|
|
|
|
String contentChuck = noteRecordSplitPieceSentence.getContentChuckSummary();
|
|
|
|
|
if (null == contentChuck || contentChuck.isEmpty()) {
|
|
|
|
|
log.warn("longTextExtractTripleInfo:同语义片段片段:{} 不存在任何分类信息,不进行后续操作...", pieceSentenceId);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询 同语义类型 对应的 提示词集合
|
|
|
|
|
List<NotePiecePrompt> notePromptList = notePiecePromptService.listPiecePromptBySplitId(noteRecordSplitPieceSentence);
|
|
|
|
|
if (CollUtil.isEmpty(notePromptList)) {
|
|
|
|
|
log.warn("longTextExtractTripleInfo:同语义片段:{},分类:{} 不属于任何提示词,不进行后续操作...", pieceSentenceId, contentChuck);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询笔录的案件信息
|
|
|
|
|
String recordSplitId = noteRecordSplitPieceSentence.getRecordSplitId();
|
|
|
|
|
NoteRecordSplit recordSplit = noteRecordSplitService.lambdaQuery().select(NoteRecordSplit::getCaseId).eq(NoteRecordSplit::getId, recordSplitId).one();
|
|
|
|
|
QueryWrapper<CasePerson> wrapper = new QueryWrapper<>();
|
|
|
|
|
wrapper.eq("case_id", recordSplit.getCaseId());
|
|
|
|
|
wrapper.eq("case_actor_flag", 1);
|
|
|
|
|
CasePerson personServiceOne = casePersonService.getOne(wrapper);
|
|
|
|
|
returnMap.put("person", personServiceOne);
|
|
|
|
|
returnMap.put("notePromptList", notePromptList);
|
|
|
|
|
return returnMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 同语义落库
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Consumer<Map<String, Object>> pieceSentenceSave() throws Exception {
|
|
|
|
|
return (noteMap) -> {
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction-Pool-pieceSentenceSave]同语义保存,当前线程是:{}", Thread.currentThread().getName());
|
|
|
|
|
String contentChuck;
|
|
|
|
|
List<NoteRecordSplitPieceSentence> recordSplitPieceSentences = (List<NoteRecordSplitPieceSentence>) noteMap.get("recordSplitPieceSentences");
|
|
|
|
|
List<PieceSentenceIdDto> noteRecordSplitPieceSentenceBySingle = (List<PieceSentenceIdDto>) noteMap.get("noteRecordSplitPieceSentenceBySingle");
|
|
|
|
|
// 保存同语义集合
|
|
|
|
|
noteRecordSplitPieceSentenceService.saveBatch(recordSplitPieceSentences);
|
|
|
|
|
|
|
|
|
|
// 更新单语句 的 长语句id
|
|
|
|
|
for (PieceSentenceIdDto pieceSentenceIdDto : noteRecordSplitPieceSentenceBySingle) {
|
|
|
|
|
List<NoteRecordSplitSentence> recordSplitSentences = getNoteRecordSplitSentences(pieceSentenceIdDto);
|
|
|
|
|
noteRecordSplitSentenceService.updateBatchById(recordSplitSentences);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存 提示词
|
|
|
|
|
NotePiecePrompt piecePrompt = notePiecePromptService.lambdaQuery().eq(NotePiecePrompt::getName, "行为人-担保-xxxx").one();
|
|
|
|
|
if (null == piecePrompt) {
|
|
|
|
|
NotePiecePrompt notePiecePrompt = getNotePiecePrompt();
|
|
|
|
|
notePiecePromptService.save(notePiecePrompt);
|
|
|
|
|
piecePrompt = notePiecePrompt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新同语义总结
|
|
|
|
|
List<NoteRecordSplitPieceSentence> noteRecordSplitPieceSentences = new ArrayList<>();
|
|
|
|
|
List<ModelPieceRecordType> modelPieceRecordTypes = new ArrayList<>();
|
|
|
|
|
List<NotePiecePromptTypeRel> notePiecePromptTypeRels = new ArrayList<>();
|
|
|
|
|
for (NoteRecordSplitPieceSentence noteRecordSplitPieceSentence : recordSplitPieceSentences) {
|
|
|
|
|
String splitPieceSentenceId = noteRecordSplitPieceSentence.getId();
|
|
|
|
|
List<NoteRecordSplitSentence> splitSentence = noteRecordSplitSentenceService.lambdaQuery()
|
|
|
|
|
.select(NoteRecordSplitSentence::getLlmGenA)
|
|
|
|
|
.isNotNull(NoteRecordSplitSentence::getLlmGenA)
|
|
|
|
|
.ne(NoteRecordSplitSentence::getLlmGenA, "无")
|
|
|
|
|
.eq(NoteRecordSplitSentence::getPieceRecordSplitId, splitPieceSentenceId)
|
|
|
|
|
.list();
|
|
|
|
|
if (null != splitSentence && !splitSentence.isEmpty()) {
|
|
|
|
|
// 更新同语义总结
|
|
|
|
|
contentChuck = splitSentence.get(0).getLlmGenA();
|
|
|
|
|
} else {
|
|
|
|
|
// 重新请求模型生成同语义句子的语义
|
|
|
|
|
List<String> noteRecordSplitAnswerList = new ArrayList<>();
|
|
|
|
|
noteRecordSplitAnswerList.add(noteRecordSplitPieceSentence.getContentChuck());
|
|
|
|
|
contentChuck = ((chatAiLongTextSingleSentenceSummary(PromptsEnum.LONG_TEXT_SINGLE_SENTENCE_SUMMARY, noteRecordSplitAnswerList).get(0)) == null) ? "无"
|
|
|
|
|
: (chatAiLongTextSingleSentenceSummary(PromptsEnum.LONG_TEXT_SINGLE_SENTENCE_SUMMARY, noteRecordSplitAnswerList).get(0).getLlmGenA());
|
|
|
|
|
}
|
|
|
|
|
NoteRecordSplitPieceSentence splitPieceSentence = new NoteRecordSplitPieceSentence();
|
|
|
|
|
splitPieceSentence.setId(splitPieceSentenceId);
|
|
|
|
|
splitPieceSentence.setContentChuckSummary(contentChuck);
|
|
|
|
|
noteRecordSplitPieceSentences.add(splitPieceSentence);
|
|
|
|
|
// 类型
|
|
|
|
|
String modelPieceRecordTypeId = DefaultIdentifierGenerator.getInstance().nextId(null).toString();
|
|
|
|
|
ModelPieceRecordType modelPieceRecordType = new ModelPieceRecordType();
|
|
|
|
|
modelPieceRecordType.setId(modelPieceRecordTypeId);
|
|
|
|
|
modelPieceRecordType.setRecordType(contentChuck);
|
|
|
|
|
modelPieceRecordType.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
|
modelPieceRecordType.setUpdateUserId(UserUtil.getUser().getId());
|
|
|
|
|
modelPieceRecordTypes.add(modelPieceRecordType);
|
|
|
|
|
// 保存 类型 提示词关系
|
|
|
|
|
String notePiecePromptTypeRelId = DefaultIdentifierGenerator.getInstance().nextId(null).toString();
|
|
|
|
|
NotePiecePromptTypeRel notePiecePromptTypeRel = new NotePiecePromptTypeRel();
|
|
|
|
|
notePiecePromptTypeRel.setId(notePiecePromptTypeRelId);
|
|
|
|
|
notePiecePromptTypeRel.setPromptId(piecePrompt.getId());
|
|
|
|
|
notePiecePromptTypeRel.setTypeId(modelPieceRecordType.getId());
|
|
|
|
|
notePiecePromptTypeRels.add(notePiecePromptTypeRel);
|
|
|
|
|
}
|
|
|
|
|
// 更新同语义句的总结(类型)
|
|
|
|
|
noteRecordSplitPieceSentenceService.updateBatchById(noteRecordSplitPieceSentences);
|
|
|
|
|
// 保存同语义总结(类型)
|
|
|
|
|
modelPieceRecordTypeService.saveBatch(modelPieceRecordTypes);
|
|
|
|
|
// 保存 类型 提示词关系
|
|
|
|
|
notePiecePromptTypeRelService.saveBatch(notePiecePromptTypeRels);
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction-Pool-pieceSentenceSave]保存类型+总结+提示词成功,当前线程是:{}", Thread.currentThread().getName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 12.三元组提取
|
|
|
|
|
// 查询同语义句
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction-Pool-pieceSentenceSave]开始同语义三元组提取。当前线程是:{}", Thread.currentThread().getName());
|
|
|
|
|
List<String> notePieceSentencesIdList = recordSplitPieceSentences.stream().map(NoteRecordSplitPieceSentence::getId).toList();
|
|
|
|
|
List<NoteRecordSplitPieceSentence> notePieceSentences = noteRecordSplitPieceSentenceService
|
|
|
|
|
.lambdaQuery()
|
|
|
|
|
.select(NoteRecordSplitPieceSentence::getId, NoteRecordSplitPieceSentence::getRecordSplitId, NoteRecordSplitPieceSentence::getContentChuck, NoteRecordSplitPieceSentence::getContentChuckSummary)
|
|
|
|
|
.in(NoteRecordSplitPieceSentence::getId, notePieceSentencesIdList)
|
|
|
|
|
.list();
|
|
|
|
|
// 遍历同语义句
|
|
|
|
|
for (NoteRecordSplitPieceSentence noteRecordSplitPieceSentence : notePieceSentences) {
|
|
|
|
|
Map<String, Object> queryPromptByType = queryPromptByType(noteRecordSplitPieceSentence);
|
|
|
|
|
if (null == queryPromptByType) {
|
|
|
|
|
log.warn("[QaAnswerLongTextTripletExtraction-Pool-pieceSentenceSave]同语义查询案件信息或提示词为null,noteRecordSplitPieceSentenceId:{},当前线程是:{}", noteRecordSplitPieceSentence.getId(), Thread.currentThread().getName());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
CasePerson mainActor = (CasePerson) queryPromptByType.get("person");
|
|
|
|
|
List<NotePiecePrompt> notePromptList = (List<NotePiecePrompt>) queryPromptByType.get("notePromptList");
|
|
|
|
|
if (null == mainActor || CollUtil.isEmpty(notePromptList)) {
|
|
|
|
|
log.warn("[QaAnswerLongTextTripletExtraction-Pool-pieceSentenceSave]该同语义句三元组提示词或案件信息缺失,noteRecordSplitPieceSentenceId:{},当前线程是:{}", noteRecordSplitPieceSentence.getId(), Thread.currentThread().getName());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Future<PieceTripleInfo>> futures = new ArrayList<>();
|
|
|
|
|
for (NotePiecePrompt notePiecePrompt : notePromptList) {
|
|
|
|
|
PieceTripleExtractTask pieceTripleExtractTask = new PieceTripleExtractTask(chatClient, mainActor, notePiecePrompt, noteRecordSplitPieceSentence);
|
|
|
|
|
Future<PieceTripleInfo> submit = PieceTripleThreadPool.executorService.submit(pieceTripleExtractTask);
|
|
|
|
|
futures.add(submit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<PieceTripleInfo> tripleInfos = new ArrayList<>();
|
|
|
|
|
try {
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction-Pool-pieceSentenceSave]当前线程{},同语义片段:{}三元组抽取任务成功提交{}个任务....", Thread.currentThread().getName(), noteRecordSplitPieceSentence.getId(), futures.size());
|
|
|
|
|
for (Future<PieceTripleInfo> future : futures) {
|
|
|
|
|
PieceTripleInfo tripleInfo = future.get();
|
|
|
|
|
if (Objects.nonNull(tripleInfo)) {
|
|
|
|
|
tripleInfos.add(tripleInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 如果有提取到三元组信息
|
|
|
|
|
if (CollUtil.isNotEmpty(tripleInfos)) {
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction-Pool-pieceSentenceSave]当前线程{},同语义片段:{}三元组提取任务执行结束...,三元组信息入库:{}", Thread.currentThread().getName(), noteRecordSplitPieceSentence.getId(), JSONUtil.toJsonStr(tripleInfos));
|
|
|
|
|
pieceTripleInfoService.saveBatch(tripleInfos);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("[QaAnswerLongTextTripletExtraction-Pool-pieceSentenceSave]当前线程{},同语义片段:{}三元组提取任务执行结束...,未提取到任何三元组信息...", Thread.currentThread().getName(), noteRecordSplitPieceSentence.getId());
|
|
|
|
|
}
|
|
|
|
|
} catch (InterruptedException | ExecutionException e) {
|
|
|
|
|
log.error("[QaAnswerLongTextTripletExtraction-Pool-pieceSentenceSave]当前线程{},同语义片段:{}三元组提取任务提交失败...", Thread.currentThread().getName(), noteRecordSplitPieceSentence.getId(), e);
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 同语义归纳 匹配
|
|
|
|
|
*
|
|
|
|
|
* @param longTextSingleSentenceSummaryDto 但语句集合
|
|
|
|
|
*/
|
|
|
|
|
private void pieceSentenceNormal(LongTextSingleSentenceSummaryDto longTextSingleSentenceSummaryDto) {
|
|
|
|
|
log.info("[pieceSentenceNormal]开始同语义归纳方法");
|
|
|
|
|
|
|
|
|
|
String contentChuck = "";
|
|
|
|
|
|
|
|
|
|
// 同语义集合
|
|
|
|
|
List<NoteRecordSplitPieceSentence> recordSplitPieceSentences = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 同语义使用单句id集合
|
|
|
|
|
List<PieceSentenceIdDto> noteRecordSplitPieceSentenceBySingle = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 笔录片段id
|
|
|
|
|
String noteRecordSplitId = longTextSingleSentenceSummaryDto.getNoteRecordSplitId();
|
|
|
|
|
// 单语句集合
|
|
|
|
|
List<NoteRecordSplitSentence> noteRecordSplitSentences = longTextSingleSentenceSummaryDto.getNoteRecordSplitSentences();
|
|
|
|
|
int noteRecordSplitSentencesSize = noteRecordSplitSentences.size();
|
|
|
|
|
|
|
|
|
|
// 获取末尾单句 N+1
|
|
|
|
|
NoteRecordSplitSentence endCombinedSentence = noteRecordSplitSentences.get(noteRecordSplitSentencesSize - 1);
|
|
|
|
|
|
|
|
|
|
Long endCombinedSentenceId = endCombinedSentence.getId();
|
|
|
|
|
ConcurrentLinkedDeque<Long> noteRecordSplitPieceSentenceDeque = new ConcurrentLinkedDeque<>();
|
|
|
|
|
noteRecordSplitPieceSentenceDeque.add(endCombinedSentenceId);
|
|
|
|
|
|
|
|
|
|
ConcurrentLinkedDeque<String> endCombinedSentenceDeque = new ConcurrentLinkedDeque<>();
|
|
|
|
|
endCombinedSentenceDeque.addLast(endCombinedSentence.getAnswer());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历单句集合
|
|
|
|
|
for (int i = noteRecordSplitSentencesSize - 2; i >= 0; i--) {
|
|
|
|
|
PieceSentenceIdDto pieceSentenceIdDto = new PieceSentenceIdDto();
|
|
|
|
|
// 获取第N句
|
|
|
|
|
NoteRecordSplitSentence currentSentence = noteRecordSplitSentences.get(i);
|
|
|
|
|
Long currentSentenceId = currentSentence.getId();
|
|
|
|
|
String currentSentenceAnswer = currentSentence.getAnswer();
|
|
|
|
|
// 对比句子语义
|
|
|
|
|
boolean inductionFlag = chatAiLongTextHomoSemanticInduction(String.valueOf(endCombinedSentenceDeque), currentSentenceAnswer);
|
|
|
|
|
if (inductionFlag) {
|
|
|
|
|
endCombinedSentenceDeque.addFirst(currentSentenceAnswer);
|
|
|
|
|
noteRecordSplitPieceSentenceDeque.addFirst(currentSentenceId);
|
|
|
|
|
} else {
|
|
|
|
|
NoteRecordSplitPieceSentence pieceSentence = setNotePieceRecordSentence(noteRecordSplitId, endCombinedSentenceDeque);
|
|
|
|
|
endCombinedSentenceDeque.remove();
|
|
|
|
|
endCombinedSentenceDeque.addLast(currentSentenceAnswer);
|
|
|
|
|
|
|
|
|
|
List<Long> longList = noteRecordSplitPieceSentenceDeque.stream().toList();
|
|
|
|
|
noteRecordSplitPieceSentenceDeque.remove();
|
|
|
|
|
noteRecordSplitPieceSentenceDeque.addLast(currentSentenceId);
|
|
|
|
|
|
|
|
|
|
pieceSentenceIdDto.setNoteRecordSplitPieceSentenceId(pieceSentence.getId());
|
|
|
|
|
pieceSentenceIdDto.setNoteRecordSplitSentenceId(longList);
|
|
|
|
|
|
|
|
|
|
recordSplitPieceSentences.add(pieceSentence);
|
|
|
|
|
noteRecordSplitPieceSentenceBySingle.add(pieceSentenceIdDto);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NoteRecordSplitPieceSentence pieceSentence = setNotePieceRecordSentence(noteRecordSplitId, endCombinedSentenceDeque);
|
|
|
|
|
recordSplitPieceSentences.add(pieceSentence);
|
|
|
|
|
noteRecordSplitPieceSentenceBySingle.add(new PieceSentenceIdDto(pieceSentence.getId(), noteRecordSplitPieceSentenceDeque.stream().toList()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 保存同语义集合
|
|
|
|
|
noteRecordSplitPieceSentenceService.saveBatch(recordSplitPieceSentences);
|
|
|
|
|
|
|
|
|
|
// 更新单语句 的 长语句id
|
|
|
|
|
for (PieceSentenceIdDto pieceSentenceIdDto : noteRecordSplitPieceSentenceBySingle) {
|
|
|
|
|
List<NoteRecordSplitSentence> recordSplitSentences = getNoteRecordSplitSentences(pieceSentenceIdDto);
|
|
|
|
|
noteRecordSplitSentenceService.updateBatchById(recordSplitSentences);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存 提示词
|
|
|
|
|
NotePiecePrompt piecePrompt = notePiecePromptService.lambdaQuery().eq(NotePiecePrompt::getName, "行为人-担保-xxxx").one();
|
|
|
|
|
if (null == piecePrompt) {
|
|
|
|
|
NotePiecePrompt notePiecePrompt = getNotePiecePrompt();
|
|
|
|
|
notePiecePromptService.save(notePiecePrompt);
|
|
|
|
|
piecePrompt = notePiecePrompt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新同语义总结
|
|
|
|
|
List<NoteRecordSplitPieceSentence> noteRecordSplitPieceSentences = new ArrayList<>();
|
|
|
|
|
List<ModelPieceRecordType> modelPieceRecordTypes = new ArrayList<>();
|
|
|
|
|
List<NotePiecePromptTypeRel> notePiecePromptTypeRels = new ArrayList<>();
|
|
|
|
|
for (NoteRecordSplitPieceSentence noteRecordSplitPieceSentence : recordSplitPieceSentences) {
|
|
|
|
|
String splitPieceSentenceId = noteRecordSplitPieceSentence.getId();
|
|
|
|
|
List<NoteRecordSplitSentence> splitSentence = noteRecordSplitSentenceService.lambdaQuery()
|
|
|
|
|
.select(NoteRecordSplitSentence::getLlmGenA)
|
|
|
|
|
.isNotNull(NoteRecordSplitSentence::getLlmGenA)
|
|
|
|
|
.ne(NoteRecordSplitSentence::getLlmGenA, "无")
|
|
|
|
|
.eq(NoteRecordSplitSentence::getPieceRecordSplitId, splitPieceSentenceId)
|
|
|
|
|
.list();
|
|
|
|
|
if (null != splitSentence && !splitSentence.isEmpty()) {
|
|
|
|
|
// 更新同语义总结
|
|
|
|
|
contentChuck = splitSentence.get(0).getLlmGenA();
|
|
|
|
|
} else {
|
|
|
|
|
// 重新请求模型生成同语义句子的语义
|
|
|
|
|
List<String> noteRecordSplitAnswerList = new ArrayList<>();
|
|
|
|
|
noteRecordSplitAnswerList.add(noteRecordSplitPieceSentence.getContentChuck());
|
|
|
|
|
contentChuck = ((chatAiLongTextSingleSentenceSummary(PromptsEnum.LONG_TEXT_SINGLE_SENTENCE_SUMMARY, noteRecordSplitAnswerList).get(0)) == null) ? "无"
|
|
|
|
|
: (chatAiLongTextSingleSentenceSummary(PromptsEnum.LONG_TEXT_SINGLE_SENTENCE_SUMMARY, noteRecordSplitAnswerList).get(0).getLlmGenA());
|
|
|
|
|
}
|
|
|
|
|
NoteRecordSplitPieceSentence splitPieceSentence = new NoteRecordSplitPieceSentence();
|
|
|
|
|
splitPieceSentence.setId(splitPieceSentenceId);
|
|
|
|
|
splitPieceSentence.setContentChuckSummary(contentChuck);
|
|
|
|
|
noteRecordSplitPieceSentences.add(splitPieceSentence);
|
|
|
|
|
// 类型
|
|
|
|
|
String modelPieceRecordTypeId = DefaultIdentifierGenerator.getInstance().nextId(null).toString();
|
|
|
|
|
ModelPieceRecordType modelPieceRecordType = new ModelPieceRecordType();
|
|
|
|
|
modelPieceRecordType.setId(modelPieceRecordTypeId);
|
|
|
|
|
modelPieceRecordType.setRecordType(contentChuck);
|
|
|
|
|
modelPieceRecordType.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
|
modelPieceRecordType.setUpdateUserId(UserUtil.getUser().getId());
|
|
|
|
|
modelPieceRecordTypes.add(modelPieceRecordType);
|
|
|
|
|
// 保存 类型 提示词关系
|
|
|
|
|
String notePiecePromptTypeRelId = DefaultIdentifierGenerator.getInstance().nextId(null).toString();
|
|
|
|
|
NotePiecePromptTypeRel notePiecePromptTypeRel = new NotePiecePromptTypeRel();
|
|
|
|
|
notePiecePromptTypeRel.setId(notePiecePromptTypeRelId);
|
|
|
|
|
notePiecePromptTypeRel.setPromptId(piecePrompt.getId());
|
|
|
|
|
notePiecePromptTypeRel.setTypeId(modelPieceRecordType.getId());
|
|
|
|
|
notePiecePromptTypeRels.add(notePiecePromptTypeRel);
|
|
|
|
|
}
|
|
|
|
|
// 更新同语义句的总结(类型)
|
|
|
|
|
noteRecordSplitPieceSentenceService.updateBatchById(noteRecordSplitPieceSentences);
|
|
|
|
|
// 保存同语义总结(类型)
|
|
|
|
|
modelPieceRecordTypeService.saveBatch(modelPieceRecordTypes);
|
|
|
|
|
// 保存 类型 提示词关系
|
|
|
|
|
notePiecePromptTypeRelService.saveBatch(notePiecePromptTypeRels);
|
|
|
|
|
log.info("[pieceSentenceNormal]关系已保存");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提示词对象
|
|
|
|
|
*
|
|
|
|
|
* @return 提示词
|
|
|
|
|
*/
|
|
|
|
|
private NotePiecePrompt getNotePiecePrompt() {
|
|
|
|
|
NotePiecePrompt notePiecePrompt = new NotePiecePrompt();
|
|
|
|
|
notePiecePrompt.setStartEntityType("行为人");
|
|
|
|
|
notePiecePrompt.setRelType("担保");
|
|
|
|
|
notePiecePrompt.setEndEntityType("xxxx");
|
|
|
|
|
notePiecePrompt.setPrompt(PromptsEnum.LONG_TEXT_TRIPLE_INFO.getContent());
|
|
|
|
|
notePiecePrompt.setStartEntityTemplate("headEntityType");
|
|
|
|
|
notePiecePrompt.setRelTemplate("relation");
|
|
|
|
|
notePiecePrompt.setEndEntityTemplate("tailEntityType");
|
|
|
|
|
notePiecePrompt.setName("行为人-担保-xxxx");
|
|
|
|
|
notePiecePrompt.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
|
notePiecePrompt.setUpdateUserId(UserUtil.getUser().getId());
|
|
|
|
|
return notePiecePrompt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param prompt 提示词
|
|
|
|
|
* @param noteRecordSplitAnswerList 长文本单句集合
|
|
|
|
|
* @return 长文本单句总结集合
|
|
|
|
|
*/
|
|
|
|
|
public List<NoteRecordSplitSentence> chatAiLongTextSingleSentenceSummary(PromptsEnum prompt, List<String> noteRecordSplitAnswerList) {
|
|
|
|
|
|
|
|
|
|
List<NoteRecordSplitSentence> noteRecordSplitSentenceArrayList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StopWatch stopWatch = new StopWatch();
|
|
|
|
|
// 分析同语义集合
|
|
|
|
|
stopWatch.start();
|
|
|
|
|
HashMap<String, Object> paramMap = new HashMap<>();
|
|
|
|
|
paramMap.put("noteRecordSplitList", noteRecordSplitAnswerList);
|
|
|
|
|
String format = StrUtil.format(prompt.getContent(), paramMap);
|
|
|
|
|
|
|
|
|
|
ChatResponse call = chatClient.call(new Prompt(new UserMessage(format)));
|
|
|
|
|
stopWatch.stop();
|
|
|
|
|
log.warn("[QaAnswerLongTextTripletExtraction-chatAiLongTextSingleSentenceSummary]长文本单句总结集合模型耗时:{}", stopWatch.getTotalTimeSeconds());
|
|
|
|
|
String content = call.getResult().getOutput().getContent();
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(content);
|
|
|
|
|
Object object = jsonObject.get("result");
|
|
|
|
|
JSONArray jsonArray = JSONArray.parseArray(object.toString());
|
|
|
|
|
List<Object> list = jsonArray.stream().toList();
|
|
|
|
|
try {
|
|
|
|
|
for (Object listObject : list) {
|
|
|
|
|
NoteRecordSplitSentence noteRecordSplitSentence = JSONUtil.toBean(String.valueOf(listObject), NoteRecordSplitSentence.class);
|
|
|
|
|
noteRecordSplitSentenceArrayList.add(noteRecordSplitSentence);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("[QaAnswerLongTextTripletExtraction-chatAiLongTextSingleSentenceSummary]长文本单句总结集合模型转换错误");
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
return noteRecordSplitSentenceArrayList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 匹配回答中的长文本
|
|
|
|
|
*
|
|
|
|
|
* @param noteRecordSplits 笔录片段集合
|
|
|
|
|
* @return 长文本集合
|
|
|
|
|
*/
|
|
|
|
|
private List<NoteRecordSplitSentence> matcherLongText(List<NoteRecordSplit> noteRecordSplits) {
|
|
|
|
|
|
|
|
|
|
// 定义正则表达式,匹配“:”,“:”
|
|
|
|
|
String regexSplit = "[::]";
|
|
|
|
|
|
|
|
|
|
// 长文本段落集合
|
|
|
|
|
List<NoteRecordSplitSentence> noteRecordSplitList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 回答中匹配的长文本段落
|
|
|
|
|
String paragraph = null;
|
|
|
|
|
|
|
|
|
|
for (NoteRecordSplit noteRecordSplit : noteRecordSplits) {
|
|
|
|
|
String noteRecordSplitId = noteRecordSplit.getId();
|
|
|
|
|
String answer = noteRecordSplit.getAnswer();
|
|
|
|
|
if (StringUtils.isEmpty(answer)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// 使用 Pattern 和 Matcher 类进行匹配
|
|
|
|
|
Pattern pattern = Pattern.compile(regexSplit);
|
|
|
|
|
Matcher matcher = pattern.matcher(answer);
|
|
|
|
|
boolean isMatch = matcher.find();
|
|
|
|
|
if (isMatch) {
|
|
|
|
|
String[] answerSplit = answer.split(regexSplit);
|
|
|
|
|
paragraph = answerSplit[1];
|
|
|
|
|
if (StringUtils.isEmpty(paragraph)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> splitSentences = splitSentences(paragraph);
|
|
|
|
|
int paragraphChar = paragraph.replace("\n", "")
|
|
|
|
|
.replace("\t", "")
|
|
|
|
|
.replace("\s", "")
|
|
|
|
|
.trim().length();
|
|
|
|
|
if (splitSentences.size() > 5 || paragraphChar > 100) {
|
|
|
|
|
// 长文本
|
|
|
|
|
for (String sentence : splitSentences) {
|
|
|
|
|
NoteRecordSplitSentence noteRecordSplitSentence = new NoteRecordSplitSentence();
|
|
|
|
|
noteRecordSplitSentence.setRecordSplitId(noteRecordSplitId);
|
|
|
|
|
noteRecordSplitSentence.setAnswer(sentence);
|
|
|
|
|
noteRecordSplitSentence.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
|
noteRecordSplitSentence.setUpdateUserId(UserUtil.getUser().getId());
|
|
|
|
|
noteRecordSplitList.add(noteRecordSplitSentence);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return noteRecordSplitList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 匹配长文本段落中的句子
|
|
|
|
|
*
|
|
|
|
|
* @param paragraph 长文本内容
|
|
|
|
|
* @return 该长文本中的句子集合
|
|
|
|
|
*/
|
|
|
|
|
private List<String> splitSentences(String paragraph) {
|
|
|
|
|
List<String> sentences = new ArrayList<>();
|
|
|
|
|
StringBuilder currentSentence = new StringBuilder();
|
|
|
|
|
for (char c : paragraph.toCharArray()) {
|
|
|
|
|
if (c == '。' || c == '?' || c == '!' || c == '.' || c == '?' || c == '!') {
|
|
|
|
|
sentences.add(currentSentence.append(c).toString().trim());
|
|
|
|
|
currentSentence.setLength(0);
|
|
|
|
|
} else {
|
|
|
|
|
currentSentence.append(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 处理段落末尾可能没有标点符号的情况
|
|
|
|
|
if (!currentSentence.isEmpty()) {
|
|
|
|
|
sentences.add(currentSentence.toString().trim());
|
|
|
|
|
}
|
|
|
|
|
return sentences;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param encCombinedSentence N+1 句
|
|
|
|
|
* @param currentSentence N句
|
|
|
|
|
* @return 长文本单句总结集合
|
|
|
|
|
*/
|
|
|
|
|
private boolean chatAiLongTextHomoSemanticInduction(String encCombinedSentence, String currentSentence) {
|
|
|
|
|
|
|
|
|
|
StopWatch stopWatch = new StopWatch();
|
|
|
|
|
// 分析同语义集合
|
|
|
|
|
stopWatch.start();
|
|
|
|
|
HashMap<String, Object> paramMap = new HashMap<>();
|
|
|
|
|
paramMap.put("encCombinedSentence", encCombinedSentence);
|
|
|
|
|
paramMap.put("currentSentence", currentSentence);
|
|
|
|
|
String format = StrUtil.format(PromptsEnum.LONG_TEXT_SINGLE_STATEMENT_WITH_SEMANTIC_JUDGMENT_PROMPT_WORD.getContent(), paramMap);
|
|
|
|
|
|
|
|
|
|
ChatResponse call = chatClient.call(new Prompt(new UserMessage(format)));
|
|
|
|
|
stopWatch.stop();
|
|
|
|
|
String content = call.getResult().getOutput().getContent();
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(content);
|
|
|
|
|
boolean result = (boolean) jsonObject.get("result");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置同语义片段集合
|
|
|
|
|
*
|
|
|
|
|
* @param noteRecordSplitId 笔录片段id
|
|
|
|
|
* @param endSentenceDequeStringDeque 同语义单句队列
|
|
|
|
|
* @return 同语义对象
|
|
|
|
|
*/
|
|
|
|
|
public NoteRecordSplitPieceSentence setNotePieceRecordSentence(String noteRecordSplitId, ConcurrentLinkedDeque<String> endSentenceDequeStringDeque) {
|
|
|
|
|
|
|
|
|
|
StringBuilder endSentenceDequeStringBuilder = new StringBuilder();
|
|
|
|
|
for (String endSentenceDeque : endSentenceDequeStringDeque) {
|
|
|
|
|
endSentenceDequeStringBuilder.append(endSentenceDeque);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String endSentenceDequeStringBuilderString = String.valueOf(endSentenceDequeStringBuilder);
|
|
|
|
|
|
|
|
|
|
String noteRecordSplitPieceSentenceId = DefaultIdentifierGenerator.getInstance().nextId(null).toString();
|
|
|
|
|
NoteRecordSplitPieceSentence noteRecordSplitPieceSentence = new NoteRecordSplitPieceSentence();
|
|
|
|
|
noteRecordSplitPieceSentence.setId(noteRecordSplitPieceSentenceId);
|
|
|
|
|
noteRecordSplitPieceSentence.setCreateUserId(UserUtil.getUser().getId());
|
|
|
|
|
noteRecordSplitPieceSentence.setUpdateUserId(UserUtil.getUser().getId());
|
|
|
|
|
noteRecordSplitPieceSentence.setRecordSplitId(noteRecordSplitId);
|
|
|
|
|
noteRecordSplitPieceSentence.setContentChuck(endSentenceDequeStringBuilderString);
|
|
|
|
|
return noteRecordSplitPieceSentence;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 并发
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public R<Object> singlePointCheck() {
|
|
|
|
|
// 检测上个线程池中是否有未完成的任务
|
|
|
|
|
ThreadPoolExecutor longTextExecutorService = LongtextThreadPool.executorService;
|
|
|
|
|
ThreadPoolExecutor pieceTripleExecutorService = PieceTripleThreadPool.executorService;
|
|
|
|
|
int longTextActiveCount = longTextExecutorService.getActiveCount();
|
|
|
|
|
boolean longTextEmpty = longTextExecutorService.getQueue().isEmpty();
|
|
|
|
|
int pieceTripleActiveCount = pieceTripleExecutorService.getActiveCount();
|
|
|
|
|
boolean pieceTripleTextEmpty = longTextExecutorService.getQueue().isEmpty();
|
|
|
|
|
if ((longTextActiveCount != 0 || !longTextEmpty) || (pieceTripleActiveCount != 0 || !pieceTripleTextEmpty)) {
|
|
|
|
|
log.error("[QaAnswerLongTextTripletExtraction-threadPoolExecutorCheck]线程池中有未完成的任务,请稍后再试");
|
|
|
|
|
return R.fail("操作过快,请稍后再试");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取单句集合
|
|
|
|
|
*
|
|
|
|
|
* @param pieceSentenceIdDto
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<NoteRecordSplitSentence> getNoteRecordSplitSentences(PieceSentenceIdDto pieceSentenceIdDto) {
|
|
|
|
|
String noteRecordSplitPieceSentenceId = pieceSentenceIdDto.getNoteRecordSplitPieceSentenceId();
|
|
|
|
|
List<Long> noteRecordSplitSentenceId = pieceSentenceIdDto.getNoteRecordSplitSentenceId();
|
|
|
|
|
List<NoteRecordSplitSentence> recordSplitSentences = new ArrayList<>();
|
|
|
|
|
for (Long recordSplitSentenceId : noteRecordSplitSentenceId) {
|
|
|
|
|
NoteRecordSplitSentence noteRecordSplitSentence = new NoteRecordSplitSentence();
|
|
|
|
|
noteRecordSplitSentence.setId(recordSplitSentenceId);
|
|
|
|
|
noteRecordSplitSentence.setPieceRecordSplitId(noteRecordSplitPieceSentenceId);
|
|
|
|
|
recordSplitSentences.add(noteRecordSplitSentence);
|
|
|
|
|
}
|
|
|
|
|
return recordSplitSentences;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|