rasa:优化updateDataset

dev_2.1.0
xueqingkun 1 year ago
parent 183d797c1e
commit d335d4c08b

@ -1,10 +1,12 @@
package com.supervision.rasa.service;
import com.supervision.rasa.pojo.dto.QuestionAnswerDTO;
import com.supervision.rasa.pojo.dto.Text2vecDataVo;
import com.supervision.rasa.pojo.dto.Text2vecMatchesReq;
import com.supervision.rasa.pojo.dto.Text2vecMatchesRes;
import java.util.List;
import java.util.Map;
public interface Text2vecService {
@ -15,6 +17,8 @@ public interface Text2vecService {
*/
boolean updateDataset(List<Text2vecDataVo> text2vecDataVoList);
boolean updateDataset(Map<String, QuestionAnswerDTO> questionAnswerDTOMap);
/**
*
* @param text2vecMatchesReq

@ -59,6 +59,27 @@ public class Text2vecServiceImpl implements Text2vecService {
return "success".equals(JSONUtil.parseObj(body).get("status"));
}
@Override
public boolean updateDataset(Map<String, QuestionAnswerDTO> questionAnswerDTOMap) {
if (CollUtil.isEmpty(questionAnswerDTOMap)){
log.info("updateDataset: questionAnswerDTOMap is empty");
return false;
}
// 更新text2vec数据信息
List<Text2vecDataVo> text2vecDataVoList = questionAnswerDTOMap.entrySet().stream()
.filter(entry -> Objects.nonNull(entry.getValue())
&& CollUtil.isNotEmpty(entry.getValue().getQuestionList())
&& CollUtil.isNotEmpty(entry.getValue().getAnswerList()))
.flatMap(entry -> entry.getValue().getQuestionList().stream()
.map(question -> new Text2vecDataVo(entry.getValue().getAnswerList().get(0), question))).collect(Collectors.toList());
if (CollUtil.isEmpty(text2vecDataVoList)){
log.info("updateDataset: text2vecDataVoList is empty");
return false;
}
return updateDataset(text2vecDataVoList);
}
@Override
public List<Text2vecMatchesRes> matches(Text2vecMatchesReq text2vecMatchesReq) {
@ -83,19 +104,9 @@ public class Text2vecServiceImpl implements Text2vecService {
log.info("question.json文件已经存在不进行text2vec数据初始化操作....");
return;
}
Map<String, QuestionAnswerDTO> intentCodeAndIdMap = rasaCmdService.getIntentCodeAndIdMap();
// 更新text2vec数据信息
List<Text2vecDataVo> text2vecDataVoList = intentCodeAndIdMap.entrySet().stream()
.filter(entry -> Objects.nonNull(entry.getValue())
&& CollUtil.isNotEmpty(entry.getValue().getQuestionList())
&& CollUtil.isNotEmpty(entry.getValue().getAnswerList()))
.flatMap(entry -> entry.getValue().getQuestionList().stream()
.map(question -> new Text2vecDataVo(entry.getValue().getAnswerList().get(0), question))).collect(Collectors.toList());
if (CollUtil.isEmpty(text2vecDataVoList)){
log.info("text2vec数据初始化失败text2vec数据为空....");
return;
}
this.updateDataset(text2vecDataVoList);
Map<String, QuestionAnswerDTO> intentCodeAndIdMap = rasaCmdService.getIntentCodeAndIdMap();
this.updateDataset(intentCodeAndIdMap);
}
}

@ -218,13 +218,7 @@ public class RasaCmdServiceImpl implements RasaCmdService {
runExec(rasaCmdArgumentVo);
// 更新text2vec数据信息
List<Text2vecDataVo> text2vecDataVoList = questionAnswerDTOMap.entrySet().stream()
.filter(entry -> Objects.nonNull(entry.getValue())
&& CollUtil.isNotEmpty(entry.getValue().getQuestionList())
&& CollUtil.isNotEmpty(entry.getValue().getAnswerList()))
.flatMap(entry -> entry.getValue().getQuestionList().stream()
.map(question -> new Text2vecDataVo(entry.getValue().getAnswerList().get(0), question))).collect(Collectors.toList());
text2vecService.updateDataset(text2vecDataVoList);
text2vecService.updateDataset(questionAnswerDTOMap);
return true;
}

Loading…
Cancel
Save