|
|
@ -1,18 +1,24 @@
|
|
|
|
package com.supervision.police.service.impl;
|
|
|
|
package com.supervision.police.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import com.supervision.police.domain.CaseTaskRecord;
|
|
|
|
import com.supervision.police.domain.CaseTaskRecord;
|
|
|
|
import com.supervision.police.domain.ModelRecordType;
|
|
|
|
import com.supervision.police.domain.ModelRecordType;
|
|
|
|
import com.supervision.police.domain.NoteRecordSplit;
|
|
|
|
import com.supervision.police.domain.NoteRecordSplit;
|
|
|
|
import com.supervision.police.service.CaseTaskRecordService;
|
|
|
|
import com.supervision.police.service.CaseTaskRecordService;
|
|
|
|
import com.supervision.police.service.RecordSplitProcessService;
|
|
|
|
import com.supervision.police.service.RecordSplitProcessService;
|
|
|
|
import com.supervision.police.service.RecordSplitClassifyService;
|
|
|
|
import com.supervision.police.service.RecordSplitClassifyService;
|
|
|
|
|
|
|
|
import com.supervision.thread.ReplacePronounTask;
|
|
|
|
|
|
|
|
import com.supervision.thread.ReplacePronounTreadPool;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.springframework.ai.ollama.OllamaChatClient;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
import java.util.concurrent.Future;
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
@ -23,6 +29,10 @@ public class RecordSplitProcessServiceImpl implements RecordSplitProcessService
|
|
|
|
|
|
|
|
|
|
|
|
private final CaseTaskRecordService caseTaskRecordService;
|
|
|
|
private final CaseTaskRecordService caseTaskRecordService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final OllamaChatClient chatClient;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${fu-hsi-config.pronouns}")
|
|
|
|
|
|
|
|
private List<String> pronouns;
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void process(List<ModelRecordType> allTypeList, List<NoteRecordSplit> splitList) {
|
|
|
|
public void process(List<ModelRecordType> allTypeList, List<NoteRecordSplit> splitList) {
|
|
|
|
// 通过异步的形式提交分类
|
|
|
|
// 通过异步的形式提交分类
|
|
|
@ -101,4 +111,78 @@ public class RecordSplitProcessServiceImpl implements RecordSplitProcessService
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<NoteRecordSplit> replacePronoun(List<NoteRecordSplit> splitList) throws InterruptedException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ReplacePronounTask> tasks = new ArrayList<>();
|
|
|
|
|
|
|
|
for (int i = 0; i < splitList.size(); i++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NoteRecordSplit noteRecordSplit = splitList.get(i);
|
|
|
|
|
|
|
|
String question = noteRecordSplit.getQuestion();
|
|
|
|
|
|
|
|
String answer = noteRecordSplit.getAnswer();
|
|
|
|
|
|
|
|
if (StrUtil.isEmpty(question) || StrUtil.isEmpty(answer)){
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!containsProcess(question,pronouns) && !containsProcess(answer,pronouns)){
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ReplacePronounTask task = buildReplacePronounTask(splitList, i);
|
|
|
|
|
|
|
|
if (null == task){
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.add(task);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Future<NoteRecordSplit>> futures = ReplacePronounTreadPool.executorService.invokeAll(tasks);
|
|
|
|
|
|
|
|
List<NoteRecordSplit> result = new ArrayList<>();
|
|
|
|
|
|
|
|
for (Future<NoteRecordSplit> future : futures) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
NoteRecordSplit noteRecordSplit = future.get();
|
|
|
|
|
|
|
|
if (Objects.nonNull(noteRecordSplit)){
|
|
|
|
|
|
|
|
result.add(noteRecordSplit);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (ExecutionException e) {
|
|
|
|
|
|
|
|
log.error("replacePronoun:代词替换任务执行失败...",e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public ReplacePronounTask buildReplacePronounTask(List<NoteRecordSplit> splitList, int index) {
|
|
|
|
|
|
|
|
if (index == 0){
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NoteRecordSplit noteRecordSplit = splitList.get(index);
|
|
|
|
|
|
|
|
if (StrUtil.isEmpty(noteRecordSplit.getQuestion())){
|
|
|
|
|
|
|
|
log.info("replacePronoun:笔录片段:{}问题为空,跳过",noteRecordSplit.getId());
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StrUtil.isEmpty(noteRecordSplit.getAnswer())){
|
|
|
|
|
|
|
|
log.info("replacePronoun:笔录片段:{}答案为空,跳过",noteRecordSplit.getId());
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<NoteRecordSplit> preSplit = index < 3 ? CollUtil.sub(splitList,0,index) : splitList.subList(index-3,index);
|
|
|
|
|
|
|
|
return new ReplacePronounTask(chatClient, preSplit, noteRecordSplit);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 判断是否包含代词
|
|
|
|
|
|
|
|
* @param str 笔录片段
|
|
|
|
|
|
|
|
* @param pronouns 代词列表
|
|
|
|
|
|
|
|
* @return 是否包含 true 包含 false 不包含
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private boolean containsProcess(String str,List<String> pronouns){
|
|
|
|
|
|
|
|
for (String pronoun : pronouns) {
|
|
|
|
|
|
|
|
if (str.contains(pronoun)) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|