完成两个新增Box需求,nlp优化
This commit is contained in:
parent
3f1f391869
commit
7021dbf588
@ -20,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* */
|
||||
// 中文词性表
|
||||
@Slf4j
|
||||
public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
public enum ActionPartSpeechEnum implements IChinesePartSpeech{
|
||||
|
||||
v(0, "动词"){
|
||||
@Override
|
||||
@ -204,15 +204,14 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
action.setAction(action.getSystemTalkAnswerConfigEntity() == null ? null : action.getSystemTalkAnswerConfigEntity().getAskKey());
|
||||
action.setDeviceUserBindEntity(actions.getLastDeviceUserBindEntity());
|
||||
actions.getActions().add(action);
|
||||
actions.setLastName(action.getName());//lastName = action.getName();
|
||||
actions.setLastDeviceUserBindEntity(action.getDeviceUserBindEntity());
|
||||
setActionsLastAction(actions, action);
|
||||
|
||||
action = new Action();
|
||||
actions.setName("");//name = "";
|
||||
actions.setName("");
|
||||
action.setLbs(new ArrayList<>());
|
||||
action.setAsk(actions.getRecordText());
|
||||
}
|
||||
actions.setName(actions.getName() + key);//name += key.getKey();
|
||||
actions.setName(actions.getName() + key);
|
||||
}
|
||||
return action;
|
||||
}
|
||||
@ -252,12 +251,11 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
List<DeviceUserBindEntity> includs,
|
||||
List<SystemTalkAnswerConfigEntity> commands){
|
||||
if(StringUtils.isNotEmpty(actions.getName())){
|
||||
//action.setName(name);//.add(name);
|
||||
SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(actions.getName(), keyGroup);
|
||||
if(entity != null){
|
||||
if(!entity.getAnswerType().equals(AskTypeEnum.COMMAND_N.getCode())){
|
||||
systemTalkAnswerConfigEntities.add(entity);
|
||||
actions.setA(1);//a = 1;
|
||||
actions.setA(1);
|
||||
}else{
|
||||
log.info("COMMAND_N自定义指令");
|
||||
}
|
||||
@ -269,21 +267,19 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
action.setAction(action.getSystemTalkAnswerConfigEntity() == null ? null : action.getSystemTalkAnswerConfigEntity().getAskKey());
|
||||
action.setDeviceUserBindEntity(actions.getLastDeviceUserBindEntity());
|
||||
actions.getActions().add(action);
|
||||
actions.setLastName(action.getName());
|
||||
actions.setLastDeviceUserBindEntity(action.getDeviceUserBindEntity());
|
||||
setActionsLastAction(actions, action);
|
||||
|
||||
action = new Action();
|
||||
actions.setName("");
|
||||
//action.setName(new ArrayList<>());
|
||||
action.setLbs(new ArrayList<>());
|
||||
action.setAsk(actions.getRecordText());
|
||||
}
|
||||
action.setName(actions.getName());
|
||||
//name = "";
|
||||
actions.setB(1);//b = 1;
|
||||
actions.setB(1);
|
||||
}
|
||||
}
|
||||
actions.setName("");//name = "";
|
||||
actions.setName("");
|
||||
return action;
|
||||
}
|
||||
},
|
||||
@ -420,7 +416,7 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
if(entity != null){
|
||||
if(!entity.getAnswerType().equals(AskTypeEnum.COMMAND_N.getCode())){
|
||||
systemTalkAnswerConfigEntities.add(entity);
|
||||
actions.setA(1);//a = 1;
|
||||
actions.setA(1);
|
||||
}else{
|
||||
log.info("COMMAND_N自定义指令");
|
||||
}
|
||||
@ -692,8 +688,7 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
action.setAction(action.getSystemTalkAnswerConfigEntity() == null ? null : action.getSystemTalkAnswerConfigEntity().getAskKey());
|
||||
action.setDeviceUserBindEntity(actions.getLastDeviceUserBindEntity());
|
||||
actions.getActions().add(action);
|
||||
actions.setLastName(action.getName());
|
||||
actions.setLastDeviceUserBindEntity(action.getDeviceUserBindEntity());
|
||||
setActionsLastAction(actions, action);
|
||||
|
||||
action = new Action();
|
||||
actions.setName("");
|
||||
@ -703,7 +698,12 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
int index = Integer.parseInt(key.replace(">", ""));
|
||||
action.setDeviceUserBindEntity(includs.get(index));
|
||||
actions.setName("");
|
||||
action.setName(action.getDeviceUserBindEntity() == null ? null : action.getDeviceUserBindEntity().getBindName());
|
||||
if(action.getDeviceUserBindEntity() != null){
|
||||
action.setName(action.getDeviceUserBindEntity().getBindName());
|
||||
action.setDeviceUserBindEntity(action.getDeviceUserBindEntity());
|
||||
setActionsLastAction(actions, action);
|
||||
}
|
||||
|
||||
actions.setB(1);
|
||||
return action;
|
||||
}
|
||||
@ -764,7 +764,7 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
}
|
||||
}
|
||||
;
|
||||
ChinesePartSpeechEnum(Integer c, String n){
|
||||
ActionPartSpeechEnum(Integer c, String n){
|
||||
code = c;
|
||||
name = n;
|
||||
}
|
||||
@ -772,6 +772,10 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
private String name;
|
||||
|
||||
|
||||
private static void setActionsLastAction(Actions actions, Action action){
|
||||
actions.setLastName(action.getName());
|
||||
actions.setLastDeviceUserBindEntity(action.getDeviceUserBindEntity());
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
@ -781,8 +785,8 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
return name;
|
||||
}
|
||||
|
||||
public static ChinesePartSpeechEnum getEnumWithCode(Integer c){
|
||||
for (ChinesePartSpeechEnum e:values()
|
||||
public static ActionPartSpeechEnum getEnumWithCode(Integer c){
|
||||
for (ActionPartSpeechEnum e:values()
|
||||
) {
|
||||
if(e.getCode().compareTo(c) == 0){
|
||||
return e;
|
||||
@ -790,9 +794,9 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
}
|
||||
return DEFAULT;
|
||||
}
|
||||
public static ChinesePartSpeechEnum getEnumWithName(String name){
|
||||
public static ActionPartSpeechEnum getEnumWithName(String name){
|
||||
|
||||
for (ChinesePartSpeechEnum e:values()
|
||||
for (ActionPartSpeechEnum e:values()
|
||||
) {
|
||||
if(e.getName().equals(name)){
|
||||
return e;
|
||||
@ -800,8 +804,8 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
}
|
||||
return DEFAULT;
|
||||
}
|
||||
public static ChinesePartSpeechEnum getWitchValue(String tag) {
|
||||
for (ChinesePartSpeechEnum e:values()
|
||||
public static ActionPartSpeechEnum getWitchValue(String tag) {
|
||||
for (ActionPartSpeechEnum e:values()
|
||||
) {
|
||||
if(tag.equals(e.toString())){
|
||||
return e;
|
||||
@ -1,6 +1,6 @@
|
||||
package com.qiuguo.iot.third.nlp;
|
||||
|
||||
import com.qiuguo.iot.third.enums.ChinesePartSpeechEnum;
|
||||
import com.qiuguo.iot.third.enums.ActionPartSpeechEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -16,7 +16,7 @@ public class NlpKey {
|
||||
public void setTagName(String tag) {
|
||||
tagName = tag;
|
||||
|
||||
ChinesePartSpeechEnum chinesePartSpeechEnum = ChinesePartSpeechEnum.getWitchValue(tag);//.valueOf(tag);
|
||||
ActionPartSpeechEnum chinesePartSpeechEnum = ActionPartSpeechEnum.getWitchValue(tag);//.valueOf(tag);
|
||||
if(chinesePartSpeechEnum != null){
|
||||
type = chinesePartSpeechEnum.getCode();
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.qiuguo.iot.third.nlp.action;
|
||||
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceUserBindEntity;
|
||||
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
|
||||
import com.qiuguo.iot.third.nlp.Nlp;
|
||||
@ -32,6 +33,8 @@ public class Actions {
|
||||
* 记录匹配到的最后一个系统配置指令
|
||||
*/
|
||||
SystemTalkAnswerConfigEntity lastSystemTalkAnswerConfigEntity;
|
||||
|
||||
|
||||
/**
|
||||
* 最后一个匹配的绑定设备和lastName同时出现
|
||||
*/
|
||||
@ -47,9 +50,14 @@ public class Actions {
|
||||
*/
|
||||
private List<Action> actions;
|
||||
|
||||
public Actions() {}
|
||||
|
||||
public Actions(Nlp nlp, String ask){
|
||||
|
||||
public void setLastSystemTalkAnswerConfigEntity(SystemTalkAnswerConfigEntity systemTalkAnswerConfigEntity){
|
||||
if(systemTalkAnswerConfigEntity != null){
|
||||
for(Action action : actions){
|
||||
if(action.getSystemTalkAnswerConfigEntity() == null
|
||||
&& StringUtils.isNotEmpty(action.getName())){
|
||||
action.setSystemTalkAnswerConfigEntity(systemTalkAnswerConfigEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,29 +2,13 @@ package com.qiuguo.iot.third.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.qiuguo.iot.base.enums.DeviceTypeEnum;
|
||||
import com.qiuguo.iot.base.enums.KeyTypeEnum;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.base.utils.WebClientUtils;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceUserBindEntity;
|
||||
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
|
||||
import com.qiuguo.iot.data.request.device.DeviceUserBindRequest;
|
||||
import com.qiuguo.iot.data.service.device.DeviceUserBindService;
|
||||
import com.qiuguo.iot.data.service.system.SystemTalkAnswerConfigService;
|
||||
import com.qiuguo.iot.third.enums.ChinesePartSpeechEnum;
|
||||
import com.qiuguo.iot.third.nlp.NlpKey;
|
||||
import com.qiuguo.iot.third.nlp.action.Action;
|
||||
import com.qiuguo.iot.third.nlp.action.Actions;
|
||||
import com.qiuguo.iot.third.nlp.entity.SystemTalkKeyAndDeviceName;
|
||||
import com.qiuguo.iot.third.request.AudioRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 算法提供的语音合成
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
package com.qiuguo.iot.third.service;
|
||||
|
||||
import com.qiuguo.iot.base.enums.KeyTypeEnum;
|
||||
import com.qiuguo.iot.base.enums.YesNo;
|
||||
import com.qiuguo.iot.third.enums.ChinesePartSpeechEnum;
|
||||
import com.qiuguo.iot.third.enums.ActionPartSpeechEnum;
|
||||
import com.qiuguo.iot.base.enums.DeviceTypeEnum;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceUserBindEntity;
|
||||
@ -12,7 +11,6 @@ import com.qiuguo.iot.data.service.device.DeviceUserBindService;
|
||||
import com.qiuguo.iot.data.service.system.SystemTalkAnswerConfigService;
|
||||
import com.qiuguo.iot.third.nlp.NlpKey;
|
||||
import com.qiuguo.iot.third.nlp.action.Action;
|
||||
import com.qiuguo.iot.third.nlp.action.ActionTime;
|
||||
import com.qiuguo.iot.third.nlp.action.Actions;
|
||||
import com.qiuguo.iot.third.nlp.entity.SystemTalkKeyAndDeviceName;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -127,7 +125,7 @@ public class NlpService {
|
||||
//空格跳过
|
||||
continue;
|
||||
}
|
||||
action = ChinesePartSpeechEnum.getEnumWithCode(key.getType()).getAction(systemTalkAnswerConfigService.getSystemTalkWithKeyGroup(),
|
||||
action = ActionPartSpeechEnum.getEnumWithCode(key.getType()).getAction(systemTalkAnswerConfigService.getSystemTalkWithKeyGroup(),
|
||||
key.getKey(),
|
||||
actions,
|
||||
action,
|
||||
@ -135,9 +133,10 @@ public class NlpService {
|
||||
includs,
|
||||
commands);
|
||||
if(actions.getA() + actions.getB() == 2){
|
||||
actions.setA(0);// = 0;
|
||||
actions.setB(0);//b = 0;
|
||||
if(systemTalkAnswerConfigEntities.size() > 0){//指令按照优先级排序
|
||||
actions.setA(0);
|
||||
actions.setB(0);
|
||||
if(systemTalkAnswerConfigEntities.size() > 0){
|
||||
//指令按照优先级排序
|
||||
systemTalkAnswerConfigEntities.sort(Comparator.comparing(SystemTalkAnswerConfigEntity::getKeyOrder));
|
||||
action.setSystemTalkAnswerConfigEntity(systemTalkAnswerConfigEntities.get(0));
|
||||
actions.setLastSystemTalkAnswerConfigEntity(action.getSystemTalkAnswerConfigEntity());
|
||||
@ -152,10 +151,10 @@ public class NlpService {
|
||||
}
|
||||
|
||||
actions.getActions().add(action);
|
||||
actions.setLastName(action.getName());//lastName = actions.getName();
|
||||
actions.setLastName(action.getName());
|
||||
actions.setLastDeviceUserBindEntity(action.getDeviceUserBindEntity());
|
||||
action = new Action();
|
||||
actions.setName("");//name = "";
|
||||
actions.setName("");
|
||||
action.setLbs(new ArrayList<>());
|
||||
action.setAsk(actions.getRecordText());
|
||||
|
||||
@ -170,7 +169,7 @@ public class NlpService {
|
||||
actions.setLastSystemTalkAnswerConfigEntity(null);
|
||||
actions.setLastName("");
|
||||
actions.setLastDeviceUserBindEntity(null);
|
||||
actions.setB(1);//b = 1;
|
||||
actions.setB(1);
|
||||
actions.setA(1);
|
||||
}else if(StringUtils.isNotEmpty(actions.getName())){
|
||||
//中途拼接到一些词,还未匹配到看是否有识别到名词
|
||||
|
||||
@ -1,11 +1,7 @@
|
||||
package com.qiuguo.iot.box.websocket.api.domain.box;
|
||||
|
||||
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
|
||||
import com.qiuguo.iot.data.resp.third.MusicResp;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.reactive.socket.WebSocketMessage;
|
||||
import org.springframework.web.reactive.socket.WebSocketSession;
|
||||
import reactor.core.publisher.FluxSink;
|
||||
|
||||
@Data
|
||||
public class BoxSession extends BaseSession {
|
||||
@ -13,5 +9,5 @@ public class BoxSession extends BaseSession {
|
||||
/**
|
||||
* TTS合成声音的声音标识
|
||||
*/
|
||||
String tts;
|
||||
String ttsId;
|
||||
}
|
||||
|
||||
@ -247,8 +247,8 @@ public class BaseWebSocketProcess {
|
||||
}
|
||||
|
||||
private Mono<Boolean> process(Actions actions, int i, BaseSession baseSession){
|
||||
if(i < actions.getActions().size()){
|
||||
Action action = actions.getActions().get(i++);
|
||||
if(i >= 0){
|
||||
Action action = actions.getActions().get(i--);
|
||||
|
||||
return process(actions, i, baseSession).flatMap(v -> {
|
||||
if(action.getSystemTalkAnswerConfigEntity() == null){
|
||||
@ -325,7 +325,7 @@ public class BaseWebSocketProcess {
|
||||
.replace("区", "").replace("县", ""));
|
||||
}else{
|
||||
//使用IP查询天气
|
||||
req.setIp("115.205.2.137");
|
||||
req.setIp(baseSession.getCustomerIP());
|
||||
}
|
||||
if(action.getTime() == null){
|
||||
action.setTime(new ActionTime());
|
||||
@ -435,7 +435,13 @@ public class BaseWebSocketProcess {
|
||||
}
|
||||
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.QIU_GUO.getCode())){
|
||||
|
||||
return sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerValue(), AskTypeEnum.TTS.getCode());
|
||||
return sendMessage(action,
|
||||
baseSession,
|
||||
action.getSystemTalkAnswerConfigEntity().getAnswerValue(),
|
||||
AskTypeEnum.TTS.getCode()).flatMap(m ->{
|
||||
//自定义只能到这里截止
|
||||
return Mono.empty();
|
||||
});
|
||||
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.USER_CONFIG.getCode())){
|
||||
SystemTalkBindUserRequest request = new SystemTalkBindUserRequest();
|
||||
request.setUserId(baseSession.getUserId());
|
||||
@ -445,10 +451,22 @@ public class BaseWebSocketProcess {
|
||||
.flatMap(entity -> {
|
||||
if(entity.getUserId() == null){
|
||||
log.info("调用默认的回答");
|
||||
return sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerValue(), AskTypeEnum.TTS.getCode());
|
||||
return sendMessage(action,
|
||||
baseSession,
|
||||
action.getSystemTalkAnswerConfigEntity().getAnswerValue(),
|
||||
AskTypeEnum.TTS.getCode()).flatMap(m ->{
|
||||
//自定义只能到这里截止
|
||||
return Mono.empty();
|
||||
});
|
||||
}else{
|
||||
log.info("调用用户匹配的回答");
|
||||
return sendMessage(action, baseSession, entity.getAnswerValue(), AskTypeEnum.TTS.getCode());
|
||||
return sendMessage(action,
|
||||
baseSession,
|
||||
entity.getAnswerValue(),
|
||||
AskTypeEnum.TTS.getCode()).flatMap(m ->{
|
||||
//自定义只能到这里截止
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -513,7 +531,6 @@ public class BaseWebSocketProcess {
|
||||
talkRecord.setDeviceId(baseSession.getDeviceId());
|
||||
return deviceUserTalkRecordService.insertDeviceUserTalkRecord(talkRecord).flatMap(integer -> {
|
||||
return toU3DMq(systemTalkBindU3d, baseSession.getUserId());
|
||||
//return Mono.just(true);
|
||||
});
|
||||
}
|
||||
|
||||
@ -541,7 +558,7 @@ public class BaseWebSocketProcess {
|
||||
return toQianWen(action, baseSession, AskTypeEnum.TTS.getCode());
|
||||
|
||||
}
|
||||
return process(actions, 0, baseSession).flatMap(vo ->{
|
||||
return process(actions, actions.getActions().size() - 1, baseSession).flatMap(vo ->{
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
@ -22,7 +22,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ReactiveValueOperations;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.socket.*;
|
||||
@ -66,6 +65,13 @@ public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSock
|
||||
return session.close();
|
||||
}
|
||||
String ip = headers.get(LogWebFilter.HEAD_IP).get(0);
|
||||
if(ip.startsWith("192.") ||
|
||||
ip.startsWith("10.") ||
|
||||
ip.startsWith("172.") ||
|
||||
ip.startsWith("127.")){
|
||||
log.info("局域网IP替换成杭州ip:115.205.2.137");
|
||||
ip = "115.205.2.137";
|
||||
}
|
||||
String signature = headers.get("signature").get(0);
|
||||
Long userId = Long.parseLong(headers.get("userId").get(0));
|
||||
Integer isBind = Integer.parseInt(headers.get("isBind").get(0));
|
||||
@ -261,7 +267,7 @@ public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSock
|
||||
});
|
||||
|
||||
}else{
|
||||
boxSession.setTts(entity.getTts());
|
||||
boxSession.setTtsId(entity.getTts());
|
||||
if(entity.getIsBind().equals(YesNo.YES.getCode())){
|
||||
//通知用户端设备绑定成功
|
||||
sendNoticeToUser(userId, "设备联网成功,设备序列号:" + dv.getSn(), AskTypeEnum.BOX_ON_LINE.getCode());
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
package com.qiuguo.iot.box.websocket.api.service;
|
||||
|
||||
public interface IActionService {
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
package com.qiuguo.iot.box.websocket.api.service.impl;
|
||||
|
||||
import com.qiuguo.iot.box.websocket.api.service.IActionService;
|
||||
|
||||
public class QianWenActionServiceImpl implements IActionService {
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user