|
|
|
@ -33,6 +33,9 @@ import java.util.*;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 多轮对话核心业务
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@ -59,6 +62,12 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
private static final String USER_PARAM = "KBQA:ASK:USER_PARAM:";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 开启多轮对话
|
|
|
|
|
*
|
|
|
|
|
* @param roundTalkReqVO 页面信息
|
|
|
|
|
* @return 返回结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public RoundTalkResVO roundTalk(RoundTalkReqVO roundTalkReqVO) {
|
|
|
|
|
String sessionId = roundTalkReqVO.getSessionId();
|
|
|
|
@ -84,11 +93,12 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
if (CollUtil.isEmpty(sessionParamDTO.getEntityValueByExtract())) {
|
|
|
|
|
// 识别实体(先从图中获取所有的节点名称,然后识别)
|
|
|
|
|
List<String> allItemNode = findItemNodeHandler.findAllItemNode();
|
|
|
|
|
List<String> extractValue = itemExtractHandler.itemExtractByPossibleItem(sessionParamDTO.getOriginalQuestion(), allItemNode);
|
|
|
|
|
|
|
|
|
|
sessionParamDTO.setEntityValueByExtract(extractValue);
|
|
|
|
|
//List<String> extractValue = itemExtractHandler.itemExtractByPossibleItem(sessionParamDTO.getOriginalQuestion(), allItemNode);
|
|
|
|
|
// 换了另外一种匹配方式
|
|
|
|
|
String extractValue = itemExtractHandler.itemExtractBusiness(sessionParamDTO.getOriginalQuestion());
|
|
|
|
|
sessionParamDTO.setEntityValueByExtract(Collections.singletonList(extractValue));
|
|
|
|
|
// 根据提取的内容,开始在知识图谱中寻找节点(首先找叶子节点,如果叶子节点有数据,直接返回,如果叶子节点没数据,再去找分支节点)
|
|
|
|
|
List<ItemLeaf> allMatchLeafNode = findItemNodeHandler.findAllMatchLeafNode(extractValue);
|
|
|
|
|
List<ItemLeaf> allMatchLeafNode = findItemNodeHandler.findAllMatchLeafNode(Collections.singletonList(extractValue));
|
|
|
|
|
// 如果找到的节点只有1个,那么说明问的就是这个节点,那么直接缓存起来进行下一步
|
|
|
|
|
if (allMatchLeafNode.size() == 1) {
|
|
|
|
|
ItemLeaf itemLeaf = allMatchLeafNode.get(0);
|
|
|
|
@ -258,7 +268,6 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
// 移除所有需要移除的路径
|
|
|
|
|
conditionPath.removeAll(toRemove);
|
|
|
|
|
}
|
|
|
|
|
System.out.println(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -293,4 +302,15 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Set<String> queryUserNeedParam(String sessionId) {
|
|
|
|
|
// 首先根据session获取需要判断的条件
|
|
|
|
|
Object sessionCache = redisTemplate.opsForValue().get(SESSION_PARAM + sessionId);
|
|
|
|
|
SessionParamDTO sessionParamDTO = BeanUtil.toBean(sessionCache, SessionParamDTO.class);
|
|
|
|
|
// 然后获取里面的数据
|
|
|
|
|
return sessionParamDTO.getEntityCountMap().keySet();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|