部分第三方会带英语自动fanyi
This commit is contained in:
parent
7610fb4115
commit
1a34082077
BIN
iot-common/iot-base/src/main/java/com/qiuguo/iot/base/.DS_Store
vendored
Normal file
BIN
iot-common/iot-base/src/main/java/com/qiuguo/iot/base/.DS_Store
vendored
Normal file
Binary file not shown.
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +1,13 @@
|
|||||||
package com.qiuguo.iot.base.utils;
|
package com.qiuguo.iot.base.utils;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class StringUtils extends cn.hutool.core.util.StrUtil{
|
public class StringUtils extends cn.hutool.core.util.StrUtil{
|
||||||
private static final String chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
private static final String chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
|
||||||
|
private static Pattern pChinese = Pattern.compile("[\u4E00-\u9FA5|\\!|\\,|\\。|\\(|\\)|\\《|\\》|\\“|\\”|\\?|\\:|\\;|\\【|\\】]");
|
||||||
/**
|
/**
|
||||||
* 获取随机字符串 0-9, a-z, A-Z
|
* 获取随机字符串 0-9, a-z, A-Z
|
||||||
* @param length 个数
|
* @param length 个数
|
||||||
@ -21,4 +25,13 @@ public class StringUtils extends cn.hutool.core.util.StrUtil{
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Boolean isContainChinese(String str){
|
||||||
|
if (StringUtils.isEmpty(str)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher m = pChinese.matcher(str);
|
||||||
|
return m.find();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,6 +49,7 @@ public class NlpService {
|
|||||||
//涂鸦设备
|
//涂鸦设备
|
||||||
request.setDeviceType(DeviceTypeEnum.ELECTRIC_SOCKET.getCode());
|
request.setDeviceType(DeviceTypeEnum.ELECTRIC_SOCKET.getCode());
|
||||||
request.setPageSize(MAX_COUT);
|
request.setPageSize(MAX_COUT);
|
||||||
|
Boolean isEng = !StringUtils.isContainChinese(text);
|
||||||
return deviceUserBindService.selectDeviceUserBindsByRequest(request).flatMap(deviceUserBindEntityPagerResult -> {
|
return deviceUserBindService.selectDeviceUserBindsByRequest(request).flatMap(deviceUserBindEntityPagerResult -> {
|
||||||
List<DeviceUserBindEntity> includs = new ArrayList<>();
|
List<DeviceUserBindEntity> includs = new ArrayList<>();
|
||||||
List<SystemTalkAnswerConfigEntity> systemIncluds = new ArrayList<>();
|
List<SystemTalkAnswerConfigEntity> systemIncluds = new ArrayList<>();
|
||||||
@ -119,7 +120,7 @@ public class NlpService {
|
|||||||
if(sysTalkKeyAndDeviceName.getType().equals(KeyTypeEnum.QIUGUO_NAME.getCode())){
|
if(sysTalkKeyAndDeviceName.getType().equals(KeyTypeEnum.QIUGUO_NAME.getCode())){
|
||||||
pinyinArray = pinyinArray.replace(sysTalkKeyAndDeviceName.getKey(), "#" + (j++) + "#");
|
pinyinArray = pinyinArray.replace(sysTalkKeyAndDeviceName.getKey(), "#" + (j++) + "#");
|
||||||
systemIncluds.add(systemTalkAnswerConfigService.getCommandList().get(sysTalkKeyAndDeviceName.getIndex()));
|
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("获取拼音异常");
|
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,
|
public Mono<Actions> getActions(String text, String recordText,
|
||||||
List<DeviceUserBindEntity> includs,
|
List<DeviceUserBindEntity> includs,
|
||||||
List<SystemTalkAnswerConfigEntity> commands,
|
List<SystemTalkAnswerConfigEntity> commands,
|
||||||
String type) {
|
String type,
|
||||||
|
Boolean isEng) {
|
||||||
|
|
||||||
return liguoNlpService.geSingletNlp(text, type).map(nlp -> {
|
return liguoNlpService.geSingletNlp(text, type).map(nlp -> {
|
||||||
Actions actions = new Actions();
|
Actions actions = new Actions();
|
||||||
|
|||||||
@ -94,7 +94,25 @@
|
|||||||
<version>4.6.4</version>
|
<version>4.6.4</version>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user