部分第三方会带英语自动fanyi

This commit is contained in:
wulin 2023-11-11 20:39:19 +08:00
parent 7610fb4115
commit 1a34082077
5 changed files with 82 additions and 3 deletions

Binary file not shown.

View File

@ -0,0 +1,46 @@
package com.qiuguo.iot.base.enums;
/*
* 动作类型
* 作者吴林
* */
// 动作类型0文本播放 1音频播放 2 U3D动作 3物联网设备动作
public enum LanguageEnum {
ENGLISH(0, "en"),
CHINESE(1, "zh"),
;
LanguageEnum(Integer c, String n){
code = c;
name = n;
}
private Integer code;
private String name;
public Integer getCode() {
return code;
}
public String getName() {
return name;
}
public static LanguageEnum getEnumWithCode(Integer c){
for (LanguageEnum e:values()
) {
if(e.getCode().compareTo(c) == 0){
return e;
}
}
return null;
}
public static LanguageEnum getEnumWithName(String name){
for (LanguageEnum e:values()
) {
if(e.getName().equals(name)){
return e;
}
}
return null;
}
}

View File

@ -1,9 +1,13 @@
package com.qiuguo.iot.base.utils;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringUtils extends cn.hutool.core.util.StrUtil{
private static final String chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static Pattern pChinese = Pattern.compile("[\u4E00-\u9FA5|\\|\\|\\。|\\|\\|\\《|\\》|\\“|\\”|\\|\\|\\|\\【|\\】]");
/**
* 获取随机字符串 0-9, a-z, A-Z
* @param length 个数
@ -21,4 +25,13 @@ public class StringUtils extends cn.hutool.core.util.StrUtil{
}
return sb.toString();
}
public static Boolean isContainChinese(String str){
if (StringUtils.isEmpty(str)) {
return false;
}
Matcher m = pChinese.matcher(str);
return m.find();
}
}

View File

@ -49,6 +49,7 @@ public class NlpService {
//涂鸦设备
request.setDeviceType(DeviceTypeEnum.ELECTRIC_SOCKET.getCode());
request.setPageSize(MAX_COUT);
Boolean isEng = !StringUtils.isContainChinese(text);
return deviceUserBindService.selectDeviceUserBindsByRequest(request).flatMap(deviceUserBindEntityPagerResult -> {
List<DeviceUserBindEntity> includs = new ArrayList<>();
List<SystemTalkAnswerConfigEntity> systemIncluds = new ArrayList<>();
@ -119,7 +120,7 @@ public class NlpService {
if(sysTalkKeyAndDeviceName.getType().equals(KeyTypeEnum.QIUGUO_NAME.getCode())){
pinyinArray = pinyinArray.replace(sysTalkKeyAndDeviceName.getKey(), "#" + (j++) + "#");
systemIncluds.add(systemTalkAnswerConfigService.getCommandList().get(sysTalkKeyAndDeviceName.getIndex()));
return getActions(pinyinArray, text, includs, systemIncluds, type);
return getActions(pinyinArray, text, includs, systemIncluds, type, isEng);
}
}
}
@ -127,7 +128,7 @@ public class NlpService {
log.info("获取拼音异常");
}
}
return getActions(pText, text, includs, systemIncluds, type);
return getActions(pText, text, includs, systemIncluds, type, isEng);
});
@ -136,7 +137,8 @@ public class NlpService {
public Mono<Actions> getActions(String text, String recordText,
List<DeviceUserBindEntity> includs,
List<SystemTalkAnswerConfigEntity> commands,
String type) {
String type,
Boolean isEng) {
return liguoNlpService.geSingletNlp(text, type).map(nlp -> {
Actions actions = new Actions();

View File

@ -94,7 +94,25 @@
<version>4.6.4</version>
</dependency>
<!-- 阿里巴巴fanyi -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alimt20181012</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea-openapi</artifactId>
<version>0.2.5</version>
</dependency>
<!-- 阿里星辰大模型-->
<dependency>
<groupId>com.alibaba.xingchen</groupId>
<artifactId>xingchen-java-client</artifactId>
<version>1.0.2</version>
<scope>compile</scope>
</dependency>
</dependencies>