完成部分时间词的解析
This commit is contained in:
parent
679532bcba
commit
c2f19ee805
@ -16,7 +16,7 @@ public class Action {
|
||||
private List<String> name;//动作对象(名词)。可能存在多个,如果有关系词连接
|
||||
private String status;//动作程度结果(名词,量词)
|
||||
|
||||
private String time;//具体时间
|
||||
private ActionTime time;//具体时间
|
||||
private List<String> lbs;//一些城市地狱名词
|
||||
|
||||
/***
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
package com.qiuguo.iot.third.nlp.action;
|
||||
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ActionTime {
|
||||
|
||||
//匹配系统的动作
|
||||
/***
|
||||
* 传过来的时间名词
|
||||
*/
|
||||
private String time;//
|
||||
/**
|
||||
* 解析后的具体日期 yyyy-MM-dd
|
||||
*/
|
||||
private String dateTime;//
|
||||
/**
|
||||
* 解析后的具体日期 yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
private String dateDetailTime;//
|
||||
|
||||
public void setTime(String t){
|
||||
LocalDateTime localDateTime;
|
||||
if(StringUtils.isNotEmpty(time)){
|
||||
localDateTime = LocalDateTime.parse(dateDetailTime);//time转
|
||||
}else{
|
||||
time = t;
|
||||
localDateTime = LocalDateTime.now();
|
||||
}
|
||||
//解析生成其他时间
|
||||
//现在,今天,明天,后天,昨天,前天,*天后,*天,
|
||||
// 下周*, *周后,*周,
|
||||
// 下个月*, *个月 *月后
|
||||
// 今年,明年,后年,去年,前年,*年 *年后
|
||||
//*分钟
|
||||
//*小时
|
||||
//*秒
|
||||
|
||||
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
if(t.equals("今天")){
|
||||
|
||||
}else if(t.equals("明天")){
|
||||
localDateTime = localDateTime.minusDays(-1);
|
||||
}else if(t.equals("后天")){
|
||||
localDateTime = localDateTime.minusDays(-2);
|
||||
}else if(t.equals("昨天")){
|
||||
localDateTime = localDateTime.minusDays(1);
|
||||
}else if(t.equals("前天")){
|
||||
localDateTime = localDateTime.minusDays(2);
|
||||
}
|
||||
dateTime = localDateTime.format(df);
|
||||
dateDetailTime = localDateTime.format(df1);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,7 @@ import com.qiuguo.iot.data.service.system.SystemTalkAnswerConfigService;
|
||||
import com.qiuguo.iot.third.nlp.INlp;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -74,7 +75,8 @@ public class NlpService {
|
||||
action.getLbs().add(key.getKey());
|
||||
}else if(key.getType().equals(ChinesePartSpeechEnum.t.getCode())){
|
||||
//解析时间关键字
|
||||
//action.setTime(key.getKey());
|
||||
action.setTime(new ActionTime());
|
||||
action.getTime().setTime(key.getKey());
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotEmpty(name)){
|
||||
|
||||
@ -113,7 +113,7 @@ public class BaseWebSocketProcess {
|
||||
//通知打开灯成功
|
||||
msg = action.getSystemTalkAnswerConfigEntity().getAnswerValue().replaceAll("#name#", deviceName);
|
||||
if(StringUtils.isNotEmpty(action.getStatus())){
|
||||
msg.replace("#value#", action.getStatus());
|
||||
msg = msg.replace("#value#", action.getStatus());
|
||||
}
|
||||
|
||||
log.info("执行指令");
|
||||
@ -137,8 +137,6 @@ public class BaseWebSocketProcess {
|
||||
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), "未找到对应的设备");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.WEATHER.getCode())){
|
||||
ThirdWeatherInfoRequest req = new ThirdWeatherInfoRequest();
|
||||
//String city = "";
|
||||
@ -154,15 +152,25 @@ public class BaseWebSocketProcess {
|
||||
log.info("查询的天气{}", JSONObject.toJSONString(t));
|
||||
TianqiapiItemResp item = null;
|
||||
|
||||
if(StringUtils.isNotEmpty(action.getTime())){
|
||||
if(StringUtils.isNotEmpty(action.getTime().getDateTime())){
|
||||
//匹配对应的日期
|
||||
for (TianqiapiItemResp itemResp : t.getData())
|
||||
{
|
||||
if(action.getTime().getDateTime().equals(itemResp.getDate())){
|
||||
item = itemResp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
item = t.getData().get(0);
|
||||
}
|
||||
String msg = "";
|
||||
if(item != null){
|
||||
//返回给客户端播报内容
|
||||
msg = t.getCity() + "天气" + item.getNarrative() + ",空气质量" + item.getAir_level()
|
||||
msg = t.getCity() + action.getTime().getTime() + "天气"
|
||||
+ item.getNarrative().replace("km / h", "千米每小时")
|
||||
+ ",空气质量" + item.getAir_level()
|
||||
+ ",湿度" + item.getHumidity() + ",最低气温" + item.getTem2();
|
||||
|
||||
}else{
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user