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;
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<ParamExtractRule> paramsRules = result.getRule().getParamsRules();
List<ParamExtractResult> 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];
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;
}
originGroupArr[index] = result.getGroup(rule.getIndexArr()[index]);
correctGroupArr[index] = result.getCorrectGroup(rule.getIndexArr()[index]);
Integer paramIndex = 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);
paramExtractResults.add(extractResult);
// 对已纠正过的数据进行记录