|
|
|
@ -49,16 +49,12 @@ public class RasaServiceImpl implements RasaService {
|
|
|
|
|
Map<String, File> ymalFileMap = new HashMap<>();
|
|
|
|
|
// 默认问答MAP
|
|
|
|
|
Map<String, QuestionAnswerDTO> questionCodeAndIdMap = new HashMap<>();
|
|
|
|
|
// 问诊工具MAP
|
|
|
|
|
Map<String, ConfigPhysicalTool> toolCodeIdMap = new HashMap<>();
|
|
|
|
|
// 辅助检查MAP
|
|
|
|
|
Map<String, ConfigAncillaryItem> ancillaryCodeIdMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
List<RuleYmlTemplate.Rule> ruleList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 开始生成各种yaml文件
|
|
|
|
|
generateNlu(diseaseId, questionCodeAndIdMap, toolCodeIdMap, ancillaryCodeIdMap, ymalFileMap);
|
|
|
|
|
generateDomain(questionCodeAndIdMap, toolCodeIdMap, ancillaryCodeIdMap, ruleList, ymalFileMap);
|
|
|
|
|
generateNlu(diseaseId, questionCodeAndIdMap, ymalFileMap);
|
|
|
|
|
generateDomain(questionCodeAndIdMap, ruleList, ymalFileMap);
|
|
|
|
|
generateRule(ruleList, ymalFileMap);
|
|
|
|
|
// 生成压缩文件
|
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
@ -81,8 +77,6 @@ public class RasaServiceImpl implements RasaService {
|
|
|
|
|
|
|
|
|
|
private void generateNlu(String diseaseId,
|
|
|
|
|
Map<String, QuestionAnswerDTO> intentCodeAndIdMap,
|
|
|
|
|
Map<String, ConfigPhysicalTool> toolCodeIdMap,
|
|
|
|
|
Map<String, ConfigAncillaryItem> itemCodeIdMap,
|
|
|
|
|
Map<String, File> ymalFileMap) {
|
|
|
|
|
// 首先生成根据意图查找到nlu文件
|
|
|
|
|
List<NluYmlTemplate.Nlu> nluList = new ArrayList<>();
|
|
|
|
@ -130,7 +124,6 @@ public class RasaServiceImpl implements RasaService {
|
|
|
|
|
nlu.setIntent(intentCode);
|
|
|
|
|
nlu.setExamples(askTemplateQuestion.getQuestion());
|
|
|
|
|
nluList.add(nlu);
|
|
|
|
|
// 添加到map中,key为意图编码,value为意图ID
|
|
|
|
|
intentCodeAndIdMap.put(intentCode, new QuestionAnswerDTO(askTemplateQuestion.getQuestion(), askDiseaseQuestionAnswer.getAnswer(), askTemplateQuestion.getDescription()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -148,8 +141,10 @@ public class RasaServiceImpl implements RasaService {
|
|
|
|
|
nlu.setIntent(toolIntent);
|
|
|
|
|
nlu.setExamples(tool.getCallOutQuestion());
|
|
|
|
|
nluList.add(nlu);
|
|
|
|
|
// 生成tool的map,key是code,value是工具对应的ID
|
|
|
|
|
toolCodeIdMap.put(toolIntent, tool);
|
|
|
|
|
// answer格式为:---tool---工具ID
|
|
|
|
|
intentCodeAndIdMap.put(toolIntent,
|
|
|
|
|
new QuestionAnswerDTO(tool.getCallOutQuestion(),
|
|
|
|
|
CollUtil.newArrayList("---tool---" + tool.getId()), "呼出-tool-" + tool.getToolName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 生成呼出的辅助检查
|
|
|
|
@ -157,19 +152,18 @@ public class RasaServiceImpl implements RasaService {
|
|
|
|
|
.isNotNull(ConfigAncillaryItem::getCode)
|
|
|
|
|
.isNotNull(ConfigAncillaryItem::getCallOutQuestion).list();
|
|
|
|
|
|
|
|
|
|
for (
|
|
|
|
|
ConfigAncillaryItem ancillary : ancillaryItemList) {
|
|
|
|
|
// 把呼出的问题全部加进去
|
|
|
|
|
for (ConfigAncillaryItem ancillary : ancillaryItemList) {
|
|
|
|
|
// 把辅助问诊的问题全部加进去
|
|
|
|
|
NluYmlTemplate.Nlu nlu = new NluYmlTemplate.Nlu();
|
|
|
|
|
String itemIntent = "ancillary_" + ancillary.getCode();
|
|
|
|
|
nlu.setIntent(itemIntent);
|
|
|
|
|
nlu.setExamples(ancillary.getCallOutQuestion());
|
|
|
|
|
nluList.add(nlu);
|
|
|
|
|
// 生成tool的map,key是item,value是工具对应的ID
|
|
|
|
|
itemCodeIdMap.put(itemIntent, ancillary);
|
|
|
|
|
// answer格式为:---ancillary---工具ID
|
|
|
|
|
intentCodeAndIdMap.put(itemIntent,
|
|
|
|
|
new QuestionAnswerDTO(ancillary.getCallOutQuestion(),
|
|
|
|
|
CollUtil.newArrayList("---ancillary---" + ancillary.getId()), "呼出-ancillary-" + ancillary.getItemName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NluYmlTemplate nluYmlTemplate = new NluYmlTemplate();
|
|
|
|
|
nluYmlTemplate.setNlu(nluList);
|
|
|
|
|
|
|
|
|
@ -180,8 +174,6 @@ public class RasaServiceImpl implements RasaService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void generateDomain(Map<String, QuestionAnswerDTO> questionCodeAndIdMap,
|
|
|
|
|
Map<String, ConfigPhysicalTool> toolCodeIdMap,
|
|
|
|
|
Map<String, ConfigAncillaryItem> ancillaryCodeIdMap,
|
|
|
|
|
List<RuleYmlTemplate.Rule> ruleList, Map<String, File> ymalFileMap) {
|
|
|
|
|
LinkedHashMap<String, List<String>> responses = new LinkedHashMap<>();
|
|
|
|
|
for (Map.Entry<String, QuestionAnswerDTO> entry : questionCodeAndIdMap.entrySet()) {
|
|
|
|
@ -191,24 +183,6 @@ public class RasaServiceImpl implements RasaService {
|
|
|
|
|
responses.put(utter, CollUtil.newArrayList(value.getAnswerList()));
|
|
|
|
|
ruleList.add(new RuleYmlTemplate.Rule(value.getDesc(), intentCode, utter));
|
|
|
|
|
}
|
|
|
|
|
// 生成呼出tool对应的回复
|
|
|
|
|
for (Map.Entry<String, ConfigPhysicalTool> entry : toolCodeIdMap.entrySet()) {
|
|
|
|
|
String intentCode = entry.getKey();
|
|
|
|
|
ConfigPhysicalTool tool = entry.getValue();
|
|
|
|
|
String utter = "utter_" + intentCode;
|
|
|
|
|
String answer = "---tool---" + tool.getId();
|
|
|
|
|
responses.put(utter, CollUtil.newArrayList(JSONUtil.toJsonStr(answer)));
|
|
|
|
|
ruleList.add(new RuleYmlTemplate.Rule(tool.getToolName(), intentCode, utter));
|
|
|
|
|
}
|
|
|
|
|
// 然后呼出辅助检查对应的回复
|
|
|
|
|
for (Map.Entry<String, ConfigAncillaryItem> entry : ancillaryCodeIdMap.entrySet()) {
|
|
|
|
|
String intentCode = entry.getKey();
|
|
|
|
|
ConfigAncillaryItem ancillary = entry.getValue();
|
|
|
|
|
String utter = "utter_" + intentCode;
|
|
|
|
|
String answer = "---ancillary---" + ancillary.getId();
|
|
|
|
|
responses.put(utter, CollUtil.newArrayList(JSONUtil.toJsonStr(answer)));
|
|
|
|
|
ruleList.add(new RuleYmlTemplate.Rule(ancillary.getItemName(), intentCode, utter));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DomainYmlTemplate domainYmlTemplate = new DomainYmlTemplate();
|
|
|
|
|