Merge remote-tracking branch 'origin/feature-BOX一期' into feature-BOX一期
This commit is contained in:
commit
51be6e3cd8
@ -66,9 +66,6 @@ public class SystemTalkAnswerConfigService extends GenericReactiveCrudService<Sy
|
||||
}
|
||||
return item;
|
||||
}).doFinally(signalType -> {
|
||||
groupCommand.sort((a, b) ->{
|
||||
return b.getAskKey().length() - a.getAskKey().length();
|
||||
});
|
||||
log.info("配置最多读取{}条,实际读取了{}条自定义回答指令,指令后参数名称{}条", MAX_COUT, group.size(), groupCommand.size());
|
||||
}).subscribeOn(Schedulers.single()).subscribe();
|
||||
|
||||
|
||||
@ -706,8 +706,16 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{
|
||||
List<SystemTalkAnswerConfigEntity> systemTalkAnswerConfigEntities,
|
||||
List<DeviceUserBindEntity> includs,
|
||||
List<SystemTalkAnswerConfigEntity> commands){
|
||||
//动词后面的名词只支持已经产生的action,后面的不要
|
||||
int index = Integer.parseInt(key.replace("#", ""));
|
||||
action.setActionCommand(commands.get(index).getAskKey());
|
||||
for (Action ac: actions.getActions()
|
||||
) {
|
||||
if(!StringUtils.isNotEmpty(ac.getActionCommand())){
|
||||
ac.setActionCommand(action.getActionCommand());
|
||||
}
|
||||
|
||||
}
|
||||
return action;
|
||||
}
|
||||
},
|
||||
|
||||
@ -18,6 +18,7 @@ public class Actions {
|
||||
* 记录名词或用户配置的词为1.一个循环后0
|
||||
*/
|
||||
int b = 0;
|
||||
|
||||
/**
|
||||
* 当前组合的名词
|
||||
*/
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package com.qiuguo.iot.third.nlp.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SystemTalkKeyAndDeviceName {
|
||||
/**
|
||||
* 关键字
|
||||
*/
|
||||
String key;
|
||||
/**
|
||||
* 所在队列中的所以呢
|
||||
*/
|
||||
int index;
|
||||
|
||||
/**
|
||||
* 类型 0 系统自定义关键字 1 用户设备名称
|
||||
*/
|
||||
Integer type;
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package com.qiuguo.iot.third.service;
|
||||
|
||||
import com.qiuguo.iot.base.enums.YesNo;
|
||||
import com.qiuguo.iot.third.enums.ChinesePartSpeechEnum;
|
||||
import com.qiuguo.iot.base.enums.DeviceTypeEnum;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
@ -12,6 +13,7 @@ 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;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
@ -45,33 +47,53 @@ public class NlpService {
|
||||
request.setPageSize(MAX_COUT);
|
||||
return deviceUserBindService.selectDeviceUserBindsByRequest(request).flatMap(deviceUserBindEntityPagerResult -> {
|
||||
if(deviceUserBindEntityPagerResult.getData().size() > 0){
|
||||
List<DeviceUserBindEntity> list = deviceUserBindEntityPagerResult.getData();
|
||||
/*List<DeviceUserBindEntity> list = deviceUserBindEntityPagerResult.getData();
|
||||
list.sort((a, b) -> {
|
||||
return b.getBindName().length() - a.getBindName().length();
|
||||
});//按照名称由长到短排序
|
||||
});//按照名称由长到短排序*/
|
||||
List<DeviceUserBindEntity> includs = new ArrayList<>();
|
||||
List<SystemTalkAnswerConfigEntity> commands = new ArrayList<>();
|
||||
String pText = text;
|
||||
List<SystemTalkKeyAndDeviceName> systemTalkKeyAndDeviceNameList = new ArrayList<>();
|
||||
int i = 0;
|
||||
//放在这里是因为用户有物联网设备才有意义
|
||||
for (SystemTalkAnswerConfigEntity entity:systemTalkAnswerConfigService.getCommandList()
|
||||
) {
|
||||
if(pText.indexOf(entity.getAskKey()) >= 0){
|
||||
//找到对应的名称
|
||||
pText = pText.replace(entity.getAskKey(), "#" + (i++) + "#");
|
||||
commands.add(entity);
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
for (DeviceUserBindEntity entity:list
|
||||
) {
|
||||
if(pText.indexOf(entity.getBindName()) >= 0){
|
||||
//找到对应的名称
|
||||
pText = pText.replace(entity.getBindName(), ">" + (i++) + ">");
|
||||
includs.add(entity);
|
||||
}
|
||||
for(SystemTalkAnswerConfigEntity entity : systemTalkAnswerConfigService.getCommandList()){
|
||||
SystemTalkKeyAndDeviceName systemTalkKeyAndDeviceName = new SystemTalkKeyAndDeviceName();
|
||||
systemTalkKeyAndDeviceName.setKey(entity.getAskKey());
|
||||
systemTalkKeyAndDeviceName.setType(0);
|
||||
systemTalkKeyAndDeviceName.setIndex(i++);
|
||||
systemTalkKeyAndDeviceNameList.add(systemTalkKeyAndDeviceName);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for(DeviceUserBindEntity entity : deviceUserBindEntityPagerResult.getData()){
|
||||
SystemTalkKeyAndDeviceName systemTalkKeyAndDeviceName = new SystemTalkKeyAndDeviceName();
|
||||
systemTalkKeyAndDeviceName.setKey(entity.getBindName());
|
||||
systemTalkKeyAndDeviceName.setType(1);
|
||||
systemTalkKeyAndDeviceName.setIndex(i++);
|
||||
systemTalkKeyAndDeviceNameList.add(systemTalkKeyAndDeviceName);
|
||||
}
|
||||
//字符由长到短排序
|
||||
systemTalkKeyAndDeviceNameList.sort((a, b) ->{
|
||||
return b.getKey().length() - a.getKey().length();
|
||||
});
|
||||
|
||||
String pText = text;
|
||||
i = 0;
|
||||
int j = 0;
|
||||
for(SystemTalkKeyAndDeviceName sysTalkKeyAndDeviceName :systemTalkKeyAndDeviceNameList){
|
||||
if(pText.indexOf(sysTalkKeyAndDeviceName.getKey()) >= 0){
|
||||
//找到对应的名称
|
||||
if(sysTalkKeyAndDeviceName.getType().equals(YesNo.YES.getCode())){
|
||||
//用户绑定设备名称
|
||||
pText = pText.replace(sysTalkKeyAndDeviceName.getKey(), ">" + (i++) + ">");
|
||||
includs.add(deviceUserBindEntityPagerResult.getData().get(sysTalkKeyAndDeviceName.getIndex()));
|
||||
}else{
|
||||
//是系统自定义动词后的名称
|
||||
pText = pText.replace(sysTalkKeyAndDeviceName.getKey(), "#" + (j++) + "#");
|
||||
commands.add(systemTalkAnswerConfigService.getCommandList().get(sysTalkKeyAndDeviceName.getIndex()));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if(includs.size() > 0) {
|
||||
return getActions(pText, text, includs, commands);
|
||||
}
|
||||
@ -90,9 +112,7 @@ public class NlpService {
|
||||
return liguoNlpService.geSingletNlp(text).map(nlp -> {
|
||||
Actions actions = new Actions();
|
||||
actions.setActions(new ArrayList<>());
|
||||
//nlp.getKeys().sort(Comparator.comparing(NlpKey::getType)); //解析,按照type从小到大排序
|
||||
Action action = new Action();
|
||||
//String name = "";
|
||||
|
||||
actions.setRecordText(recordText);
|
||||
action.setLbs(new ArrayList<>());
|
||||
@ -101,6 +121,13 @@ public class NlpService {
|
||||
|
||||
for (NlpKey key : nlp.getKeys()
|
||||
) {
|
||||
action = ChinesePartSpeechEnum.getEnumWithCode(key.getType()).getAction(systemTalkAnswerConfigService.getSystemTalkWithKeyGroup(),
|
||||
key.getKey(),
|
||||
actions,
|
||||
action,
|
||||
systemTalkAnswerConfigEntities,
|
||||
includs,
|
||||
commands);
|
||||
if(actions.getA() + actions.getB() == 2){
|
||||
actions.setA(0);// = 0;
|
||||
actions.setB(0);//b = 0;
|
||||
@ -130,34 +157,39 @@ public class NlpService {
|
||||
actions.setLastDeviceUserBindEntity(action.getDeviceUserBindEntity());
|
||||
action = new Action();
|
||||
actions.setName("");//name = "";
|
||||
//action.setName(new ArrayList<>());
|
||||
action.setLbs(new ArrayList<>());
|
||||
action.setAsk(actions.getRecordText());
|
||||
|
||||
}
|
||||
|
||||
action = ChinesePartSpeechEnum.getEnumWithCode(key.getType()).getAction(systemTalkAnswerConfigService.getSystemTalkWithKeyGroup(),
|
||||
key.getKey(),
|
||||
actions,
|
||||
action,
|
||||
systemTalkAnswerConfigEntities,
|
||||
includs,
|
||||
commands);
|
||||
|
||||
}
|
||||
//下面判断最后一个名词
|
||||
if(StringUtils.isNotEmpty(actions.getName())){
|
||||
if(StringUtils.isNotEmpty(action.getName()) && actions.getA() == 0){
|
||||
//这说明已经匹配到设备了,但是没有匹配到动作
|
||||
action.setSystemTalkAnswerConfigEntity(actions.getLastSystemTalkAnswerConfigEntity());
|
||||
action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey());
|
||||
actions.setLastSystemTalkAnswerConfigEntity(null);
|
||||
actions.setLastName("");
|
||||
actions.setLastDeviceUserBindEntity(null);
|
||||
actions.setB(1);//b = 1;
|
||||
actions.setA(1);
|
||||
}else if(StringUtils.isNotEmpty(actions.getName())){
|
||||
//中途拼接到一些词,还未匹配到看是否有识别到名词
|
||||
//先看是否为自定义指令
|
||||
SystemTalkAnswerConfigEntity entity = systemTalkAnswerConfigService.getSystemTalkWithKey(actions.getName());
|
||||
if(entity != null){
|
||||
systemTalkAnswerConfigEntities.add(entity);
|
||||
actions.setA(1);//a = 1;
|
||||
}else{
|
||||
}else{//这里没雨匹配到设备,需要执行时查询数据库
|
||||
action.setName(actions.getName());//.add(name);
|
||||
actions.setB(1);//b = 1;
|
||||
actions.setLastSystemTalkAnswerConfigEntity(null);
|
||||
actions.setLastName("");
|
||||
actions.setLastDeviceUserBindEntity(null);
|
||||
}
|
||||
}else{
|
||||
if(StringUtils.isNotEmpty(actions.getLastName())){
|
||||
}else if(actions.getA() == 1){
|
||||
//匹配到动作,但是没有设备名称
|
||||
if(StringUtils.isNotEmpty(actions.getLastName())){//如果还有多就用最后一次匹配到的设备信息
|
||||
action.setName(actions.getLastName());//.add(lastName);
|
||||
action.setDeviceUserBindEntity(actions.getLastDeviceUserBindEntity());
|
||||
actions.setB(1);//b = 1;
|
||||
|
||||
@ -13,6 +13,7 @@ import com.qiuguo.iot.box.websocket.api.filter.LogMdcConfiguration;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceUserBindEntity;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceUserTalkRecordEntity;
|
||||
import com.qiuguo.iot.data.entity.system.SystemTalkBindDeviceEntity;
|
||||
import com.qiuguo.iot.data.request.TongYiCommunicationRest;
|
||||
import com.qiuguo.iot.data.request.device.DeviceUserBindRequest;
|
||||
import com.qiuguo.iot.data.request.system.SystemTalkBindDeviceRequest;
|
||||
import com.qiuguo.iot.data.request.third.ThirdWeatherInfoRequest;
|
||||
@ -27,10 +28,7 @@ import com.qiuguo.iot.third.nlp.action.ActionTime;
|
||||
import com.qiuguo.iot.third.nlp.action.Actions;
|
||||
import com.qiuguo.iot.third.query.TuyaQuery;
|
||||
import com.qiuguo.iot.third.resp.SongInfoResponse;
|
||||
import com.qiuguo.iot.third.service.MusicService;
|
||||
import com.qiuguo.iot.third.service.NlpService;
|
||||
import com.qiuguo.iot.third.service.TuyaDeviceService;
|
||||
import com.qiuguo.iot.third.service.WeatherService;
|
||||
import com.qiuguo.iot.third.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.slf4j.MDC;
|
||||
@ -38,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.reactive.socket.WebSocketSession;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.swing.*;
|
||||
@ -71,6 +70,9 @@ public class BaseWebSocketProcess {
|
||||
@Autowired
|
||||
protected MusicService musicService;
|
||||
|
||||
@Autowired
|
||||
protected QWenService qwenService;
|
||||
|
||||
|
||||
protected static ConcurrentHashMap<Long, BaseSession> userGroup = new ConcurrentHashMap<>();
|
||||
|
||||
@ -85,10 +87,23 @@ public class BaseWebSocketProcess {
|
||||
log.info("匹配到自定义指令{}", action.getSystemTalkAnswerConfigEntity());
|
||||
if(action.getSystemTalkAnswerConfigEntity() == null){
|
||||
log.info("调用千问");
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(0);
|
||||
resp.setText("暂时无法理解,我还在努力学习中");
|
||||
sendMessage(action, baseSession, resp);
|
||||
|
||||
TongYiCommunicationRest tongYiCommunicationRest = new TongYiCommunicationRest();
|
||||
tongYiCommunicationRest.setText(action.getAsk());
|
||||
tongYiCommunicationRest.setStatus("2");
|
||||
if(this instanceof BoxWebSocketHandler){
|
||||
tongYiCommunicationRest.setOnlyId(baseSession.getSn());
|
||||
}else{
|
||||
tongYiCommunicationRest.setOnlyId(baseSession.getUserId().toString());
|
||||
}
|
||||
qwenService.communication(tongYiCommunicationRest).map(data ->{
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(0);
|
||||
resp.setText(data.getResut());
|
||||
sendMessage(action, baseSession, resp);
|
||||
return data;
|
||||
}).subscribeOn(Schedulers.boundedElastic()).subscribe();
|
||||
//
|
||||
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.IOT.getCode())){
|
||||
|
||||
if(StringUtils.isNotEmpty(action.getName())){
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user