rasa:优化updateDataset

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

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

@ -59,6 +59,27 @@ public class Text2vecServiceImpl implements Text2vecService {
return "success".equals(JSONUtil.parseObj(body).get("status")); 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 @Override
public List<Text2vecMatchesRes> matches(Text2vecMatchesReq text2vecMatchesReq) { public List<Text2vecMatchesRes> matches(Text2vecMatchesReq text2vecMatchesReq) {
@ -83,19 +104,9 @@ public class Text2vecServiceImpl implements Text2vecService {
log.info("question.json文件已经存在不进行text2vec数据初始化操作...."); log.info("question.json文件已经存在不进行text2vec数据初始化操作....");
return; return;
} }
Map<String, QuestionAnswerDTO> intentCodeAndIdMap = rasaCmdService.getIntentCodeAndIdMap();
// 更新text2vec数据信息 // 更新text2vec数据信息
List<Text2vecDataVo> text2vecDataVoList = intentCodeAndIdMap.entrySet().stream() Map<String, QuestionAnswerDTO> intentCodeAndIdMap = rasaCmdService.getIntentCodeAndIdMap();
.filter(entry -> Objects.nonNull(entry.getValue()) this.updateDataset(intentCodeAndIdMap);
&& 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);
} }
} }

@ -218,13 +218,7 @@ public class RasaCmdServiceImpl implements RasaCmdService {
runExec(rasaCmdArgumentVo); runExec(rasaCmdArgumentVo);
// 更新text2vec数据信息 // 更新text2vec数据信息
List<Text2vecDataVo> text2vecDataVoList = questionAnswerDTOMap.entrySet().stream() text2vecService.updateDataset(questionAnswerDTOMap);
.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);
return true; return true;
} }

Loading…
Cancel
Save