This commit is contained in:
tiger_zhou 2023-04-12 10:49:46 +08:00
parent 851b259f81
commit 91985fd241

View File

@ -1,5 +1,7 @@
package club.joylink.rtss.services.voice.discriminate; 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.services.voice.VoiceService;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.discriminate.ParamExtractResult; 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.util.PinYinUtil;
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult; import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -24,6 +28,7 @@ import java.util.regex.Pattern;
* 语音文件解析服务 * 语音文件解析服务
*/ */
@Service @Service
@Slf4j
public class VoiceParseServiceImpl implements VoiceParseService { public class VoiceParseServiceImpl implements VoiceParseService {
/** /**
@ -128,26 +133,23 @@ public class VoiceParseServiceImpl implements VoiceParseService {
List<ParamExtractRule> paramsRules = result.getRule().getParamsRules(); List<ParamExtractRule> paramsRules = result.getRule().getParamsRules();
List<ParamExtractResult> paramExtractResults = new ArrayList<>(paramsRules.size()); List<ParamExtractResult> paramExtractResults = new ArrayList<>(paramsRules.size());
int groupSize = result.getGroupCount(); int groupSize = result.getGroupCount();
// ParamExtractResult extractResult = null;
// String[] originGroupArr = null, correctGroupArr = null;
for (ParamExtractRule rule : paramsRules) { for (ParamExtractRule rule : paramsRules) {
String[] originGroupArr = null, correctGroupArr = null; if(ArrayUtils.isEmpty(rule.getIndexArr())){
if (rule.getIndexArr() != null) { // 如果定位信息不为空 log.error("参数解析配置数据错误原文:[{}],匹配规则:[{}]",result.getOriginContent(),result.getRule().getKeyWordRules());
originGroupArr = new String[rule.getIndexArr().length]; throw new BusinessException(BusinessExceptionAssertEnum.VOICE_COMMAND_CONFIG_NULL);
correctGroupArr = new String[rule.getIndexArr().length]; }
String[] originGroupArr = new String[rule.getIndexArr().length];
String[] correctGroupArr = new String[rule.getIndexArr().length];
for (int index = 0, len = originGroupArr.length; index < len; index ++) { for (int index = 0, len = originGroupArr.length; index < len; index ++) {
if (groupSize < rule.getIndexArr()[index]) { if (groupSize < rule.getIndexArr()[index]) {
result.setSuccess(false); result.setSuccess(false);
result.setMsg("提取参数出错"); result.setMsg("提取参数出错");
return; return;
} }
originGroupArr[index] = result.getGroup(rule.getIndexArr()[index]); Integer paramIndex = rule.getIndexArr()[index];
correctGroupArr[index] = result.getCorrectGroup(rule.getIndexArr()[index]); originGroupArr[index] = result.getGroup(paramIndex);
correctGroupArr[index] = result.getCorrectGroup(paramIndex);
} }
} /*else { // 如果定位信息为空则将参数置空
originGroupArr = null;
correctGroupArr = null;
}*/
ParamExtractResult extractResult = rule.getParseRule().matchParam(simulation, originGroupArr, correctGroupArr); ParamExtractResult extractResult = rule.getParseRule().matchParam(simulation, originGroupArr, correctGroupArr);
paramExtractResults.add(extractResult); paramExtractResults.add(extractResult);
// 对已纠正过的数据进行记录 // 对已纠正过的数据进行记录