From 91985fd24176426d3ee58d0a50c0e8eb3e66c65b Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Wed, 12 Apr 2023 10:49:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discriminate/VoiceParseServiceImpl.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/club/joylink/rtss/services/voice/discriminate/VoiceParseServiceImpl.java b/src/main/java/club/joylink/rtss/services/voice/discriminate/VoiceParseServiceImpl.java index 3cf4b7d0a..e47a82df0 100644 --- a/src/main/java/club/joylink/rtss/services/voice/discriminate/VoiceParseServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/voice/discriminate/VoiceParseServiceImpl.java @@ -1,5 +1,7 @@ package club.joylink.rtss.services.voice.discriminate; +import club.joylink.rtss.exception.BusinessException; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.voice.VoiceService; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.discriminate.ParamExtractResult; @@ -9,6 +11,8 @@ import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateRule; import club.joylink.rtss.util.PinYinUtil; import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult; import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ArrayUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -24,6 +28,7 @@ import java.util.regex.Pattern; * 语音文件解析服务 */ @Service +@Slf4j public class VoiceParseServiceImpl implements VoiceParseService { /** @@ -128,26 +133,23 @@ public class VoiceParseServiceImpl implements VoiceParseService { List paramsRules = result.getRule().getParamsRules(); List paramExtractResults = new ArrayList<>(paramsRules.size()); int groupSize = result.getGroupCount(); -// ParamExtractResult extractResult = null; -// String[] originGroupArr = null, correctGroupArr = null; for (ParamExtractRule rule : paramsRules) { - String[] originGroupArr = null, correctGroupArr = null; - if (rule.getIndexArr() != null) { // 如果定位信息不为空 - originGroupArr = new String[rule.getIndexArr().length]; - correctGroupArr = new String[rule.getIndexArr().length]; - for (int index = 0, len = originGroupArr.length; index < len; index ++) { - if (groupSize < rule.getIndexArr()[index]) { - result.setSuccess(false); - result.setMsg("提取参数出错"); - return; - } - originGroupArr[index] = result.getGroup(rule.getIndexArr()[index]); - correctGroupArr[index] = result.getCorrectGroup(rule.getIndexArr()[index]); + if(ArrayUtils.isEmpty(rule.getIndexArr())){ + log.error("参数解析配置数据错误原文:[{}],匹配规则:[{}]",result.getOriginContent(),result.getRule().getKeyWordRules()); + throw new BusinessException(BusinessExceptionAssertEnum.VOICE_COMMAND_CONFIG_NULL); + } + String[] originGroupArr = new String[rule.getIndexArr().length]; + String[] correctGroupArr = new String[rule.getIndexArr().length]; + for (int index = 0, len = originGroupArr.length; index < len; index ++) { + if (groupSize < rule.getIndexArr()[index]) { + result.setSuccess(false); + result.setMsg("提取参数出错"); + return; } - } /*else { // 如果定位信息为空,则将参数置空 - originGroupArr = null; - correctGroupArr = null; - }*/ + Integer paramIndex = rule.getIndexArr()[index]; + originGroupArr[index] = result.getGroup(paramIndex); + correctGroupArr[index] = result.getCorrectGroup(paramIndex); + } ParamExtractResult extractResult = rule.getParseRule().matchParam(simulation, originGroupArr, correctGroupArr); paramExtractResults.add(extractResult); // 对已纠正过的数据进行记录