Commit 518f9163 by hxw

routine

parent f0e522d1
...@@ -352,7 +352,6 @@ public class SqlHelper { ...@@ -352,7 +352,6 @@ public class SqlHelper {
id = rs.getInt(1); id = rs.getInt(1);
categoryMap.put(nameList.get(iterNum), id); categoryMap.put(nameList.get(iterNum), id);
iterNum++; iterNum++;
} }
......
...@@ -17,11 +17,21 @@ public class ChatCache implements DisposableBean { ...@@ -17,11 +17,21 @@ public class ChatCache implements DisposableBean {
private String chatKey = "不知道"; private String chatKey = "不知道";
private String botAccount = "";
private Map<String, String> infoPoint = null; private Map<String, String> infoPoint = null;
private GameEnv gameEnv = null; private GameEnv gameEnv = null;
private boolean reloading = false; private boolean reloading = false;
public String getBotAccount() {
return botAccount;
}
public void setBotAccount(String botAccount) {
this.botAccount = botAccount;
}
public boolean isReloading() { public boolean isReloading() {
return reloading; return reloading;
} }
...@@ -76,6 +86,7 @@ public class ChatCache implements DisposableBean { ...@@ -76,6 +86,7 @@ public class ChatCache implements DisposableBean {
} }
String k; String k;
this.botAccount = userInfo.botAccount;
infoPoint = new HashMap<String, String>(); infoPoint = new HashMap<String, String>();
Iterator<String> iit = userInfo.varInitialMap.keySet().iterator(); Iterator<String> iit = userInfo.varInitialMap.keySet().iterator();
while (iit.hasNext()) { while (iit.hasNext()) {
......
...@@ -49,13 +49,15 @@ public class PlotConstructor extends ElementConstructor { ...@@ -49,13 +49,15 @@ public class PlotConstructor extends ElementConstructor {
public void construct(JSONObject jsonObject, UserInfo userinfo) { public void construct(JSONObject jsonObject, UserInfo userinfo) {
try { try {
addGameStartPlot(jsonObject);
JSONArray plots = jsonObject.getJSONArray("plots"); JSONArray plots = jsonObject.getJSONArray("plots");
String start = (String) jsonObject.get("start"), startCondition; String start = (String) jsonObject.get("start"), startCondition;
JSONObject returnMessage = null; JSONObject returnMessage = null;
this.plots = plots; this.plots = plots;
constructAdjList(plots); constructAdjList(plots);
...@@ -163,17 +165,20 @@ public class PlotConstructor extends ElementConstructor { ...@@ -163,17 +165,20 @@ public class PlotConstructor extends ElementConstructor {
String startPlace = ((String)root.get("place")).split("\\+")[0]; String startPlace = ((String)root.get("place")).split("\\+")[0];
String startTaskLine = String.format(PlotConstructor.TASK_LINE, startPlace);
String startTaskCondition = String.format(PlotConstructor.TASK_CONDITION, startPlace); String startTaskCondition = String.format(PlotConstructor.TASK_CONDITION, startPlace);
String startTaskReply = String.format(PlotConstructor.TASK_REPLY, startPlace); String startTaskReply = String.format(PlotConstructor.TASK_REPLY, startPlace);
varInitialMap.put("site", startPlace); varInitialMap.put("site", startPlace);
varInitialMap.put(startTaskLine, rootId);
varInitialMap.put(startTaskCondition, ""); varInitialMap.put(startTaskCondition, "");
varInitialMap.put(startTaskReply, ""); varInitialMap.put(startTaskReply, "");
conditionDescription.put(startTaskLine, startTaskLine);
conditionDescription.put(startTaskCondition,startTaskCondition); conditionDescription.put(startTaskCondition,startTaskCondition);
conditionDescription.put(startTaskReply, startTaskReply); conditionDescription.put(startTaskReply, startTaskReply);
generateStartGame(root, jsonObject, startPlace, conditionName); //generateStartGame(root, jsonObject, startPlace, conditionName);
Queue<JSONObject> queue = new LinkedList<JSONObject>(); Queue<JSONObject> queue = new LinkedList<JSONObject>();
Map<String, String> autoJumpUpdateKnowledge = new HashMap<String, String >(); Map<String, String> autoJumpUpdateKnowledge = new HashMap<String, String >();
...@@ -418,6 +423,8 @@ public class PlotConstructor extends ElementConstructor { ...@@ -418,6 +423,8 @@ public class PlotConstructor extends ElementConstructor {
if (curPremiseList.size() == 0 && historyPremiseList.size() == 0){ if (curPremiseList.size() == 0 && historyPremiseList.size() == 0){
unconditionalPlotProcess(jConfig, nextCondition); unconditionalPlotProcess(jConfig, nextCondition);
} }
if (branchNode.getBoolean("higherPriority") != null && branchNode.getBoolean("higherPriority"))
jConfig.setAuxiliaryPriority("3");
jConfigList.add(jConfig); jConfigList.add(jConfig);
...@@ -490,12 +497,13 @@ public class PlotConstructor extends ElementConstructor { ...@@ -490,12 +497,13 @@ public class PlotConstructor extends ElementConstructor {
* 待激活列表,用于qa问答 * 待激活列表,用于qa问答
*/ */
//处于激活状态,其他的属于待激活状态,jStatus这一条不设为1,而是0
jConfig = new JConfig(" ", " ", "activate,post::gameQA(" + QA_URL+ ")", "", "unknown4,unknown3,unknown2,unknown1,common_answer", ""); jConfig = new JConfig(" ", " ", "activate,post::gameQA(" + QA_URL+ ")", "", "unknown4,unknown3,unknown2,unknown1,common_answer", "");
jConfig.setNextStepStatus("active"); jConfig.setNextStepStatus("active");
jConfig.setjStatus(1);
jConfig.setAuxiliaryPriority("0"); jConfig.setAuxiliaryPriority("0");
jConfigList.add(jConfig); jConfigList.add(jConfig);
jConfig = new JConfig( jConfig = new JConfig(
" ", "qa_status::match-Include=not_found", "match,return-0", "{unknownText-2}", " ", "" " ", "qa_status::match-Include=not_found", "match,return-0", "{unknownText-2}", " ", ""
); );
...@@ -622,6 +630,46 @@ public class PlotConstructor extends ElementConstructor { ...@@ -622,6 +630,46 @@ public class PlotConstructor extends ElementConstructor {
} }
void addGameStartPlot(JSONObject gameElements){
JSONObject startPlot = new JSONObject();
startPlot.put("id", "start");
startPlot.put("conditionName", "start_options");
startPlot.put("place", "哪呢? 还没开始呢");
startPlot.put("branch", new JSONArray());
JSONObject branch1 = new JSONObject();
branch1.put("curPremise", new JSONArray(){
{
add("start_options::match-Include=+开始+开始游戏+继续游戏+继续+重新开始");
}
});
branch1.get("curPremise");
branch1.put("higherPriority", true);
branch1.put("hisPremise", new JSONArray());
branch1.put("reply", gameElements.get("plotStartText"));
branch1.put("updateKnowledge", new JSONObject(){
{
put("unknownText", gameElements.get("firstUnknownText"));
}
});
branch1.put("nextPlotId", gameElements.get("start"));
branch1.put("includeCurInfo", false);
if(gameElements.get("startAutoJump") != null)
branch1.put("autoJump", gameElements.get("startAutoJump"));
else
branch1.put("autoJump", false);
startPlot.getJSONArray("branch").add(branch1);
gameElements.getJSONArray("plots").add(startPlot);
gameElements.put("start", "start");
gameElements.put("firstUnknownText", "请说开始游戏或者继续游戏");
}
//如果是无条件剧情,那么需要跟着一个激活操作 //如果是无条件剧情,那么需要跟着一个激活操作
......
...@@ -7,6 +7,7 @@ import com.qiwu.chatbotbackend.GameEnvironment.ObjectFileUtil; ...@@ -7,6 +7,7 @@ import com.qiwu.chatbotbackend.GameEnvironment.ObjectFileUtil;
import com.qiwu.chatbotbackend.GameEnvironment.Util; import com.qiwu.chatbotbackend.GameEnvironment.Util;
import com.qiwu.chatbotbackend.entity.ChatCache; import com.qiwu.chatbotbackend.entity.ChatCache;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import org.apache.catalina.User;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import java.io.*; import java.io.*;
...@@ -24,76 +25,11 @@ public class ChatCacheController { ...@@ -24,76 +25,11 @@ public class ChatCacheController {
private static String CHAT_CACHE_DIR = "ChatCache"; private static String CHAT_CACHE_DIR = "ChatCache";
private static String ENV_PATH = CHAT_CACHE_DIR + "/%s env.data"; private static String ENV_PATH = CHAT_CACHE_DIR + "/%s-env.data";
private static String INFO_PATH = CHAT_CACHE_DIR + "/%s info.data"; private static String INFO_PATH = CHAT_CACHE_DIR + "/%s-info.data";
/**
* 通过chat_key获得后台保存的历史信息点
* chatCache:存储了chatKye相对应的对话记录(历史信息点)
*
* @return 历史信息点,对话过程中引擎提取的用户信息
*/
// public static synchronized Map<String, String> getChatCache(String chatKey, ServletContext context) {
//
// GameEnv gameEnv = new GameEnv(chatKey);
// Map<String, String> historyInfoPoint = null;
// Map<String, Map<String, String>> chatCache = null;
// if (context.getAttribute("chatCache") == null) {
// chatCache = new HashMap<String, Map<String, String>>();
// context.setAttribute("chatCache", chatCache);
// } else {
// chatCache = (Map<String, Map<String, String>>) context.getAttribute("chatCache");
// }
// String chatkey;
//
//
// try {
// historyInfoPoint = chatCache.get(chatKey);
// //historyInfoPoint = (Map<String, String>) context.getAttribute("chat_key+"+userinfo.userName);
// } catch (Exception e) {
//
// //可整合
// historyInfoPoint = null;
//
// }
//
// return historyInfoPoint;
// }
/** public static synchronized boolean saveChatCache(String chatKey, ChatCache chatCache) throws IOException {
* chatChche中每个chatkey都有对应的最后更新时间,如果最后更新时间已经是x分钟前(超时),就清除该chatKey的数据
*/
// public static synchronized void updateChatCache4Delete(ServletContext context) {
// String chatKey;
// long lastChatTime, now;
// Map<String, String> history = new HashMap<String, String>();
// Map<String, Map<String, String>> chatCache = (Map<String, Map<String, String>>) context.getAttribute("chatCache");
//
//
// Iterator<String> it = chatCache.keySet().iterator();
// while (it.hasNext()) {
// chatKey = it.next();
// history = chatCache.get(chatKey);
// lastChatTime = Long.valueOf(history.get("lastUpdateTime"));
// now = System.currentTimeMillis();
// if (now - lastChatTime > 300000) {
// it.remove();
// }
// }
// context.setAttribute("chatCache", chatCache);
// }
/**
* 根据chatKey更新chatCache的数据,并修改最后更新时间
*/
// public static synchronized void updateChatCache4Insert(Map<String, String[]> curInfoPoint, Map<String, String> historyInfoPoint, ServletContext context) {
// historyInfoPoint.put("lastUpdateTime", String.valueOf(System.currentTimeMillis()));
// Map<String, Map<String, String>> keyCache = (Map<String, Map<String, String>>) context.getAttribute("chatCache");
// keyCache.put(curInfoPoint.get("chat_key")[0], historyInfoPoint);
// context.setAttribute("chatCache", keyCache);
// }
public static boolean saveChatCache(String chatKey, ChatCache chatCache) throws IOException {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"); DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
String nowStr = now .format(format); String nowStr = now .format(format);
...@@ -107,10 +43,10 @@ public class ChatCacheController { ...@@ -107,10 +43,10 @@ public class ChatCacheController {
if (!dir.exists()) if (!dir.exists())
dir.mkdir(); dir.mkdir();
ObjectFileUtil.writeObjectToFile(chatCache.getGameEnv(), String.format(ENV_PATH, chatKey.split("-")[0])); ObjectFileUtil.writeObjectToFile(chatCache.getGameEnv(), String.format(ENV_PATH, chatKey));
File file = new File(String.format(INFO_PATH, chatKey.split("-")[0])); File file = new File(String.format(INFO_PATH, chatKey));
FileWriter fw = new FileWriter(file); FileWriter fw = new FileWriter(file);
String jsonString = JSON.toJSONString(chatCache.getInfoPoint()); String jsonString = JSON.toJSONString(chatCache.getInfoPoint());
...@@ -119,13 +55,14 @@ public class ChatCacheController { ...@@ -119,13 +55,14 @@ public class ChatCacheController {
} catch (Exception e) { } catch (Exception e) {
System.out.println("游戏存档时发生异常"); System.out.println("游戏存档时发生异常");
e.printStackTrace();
saveFlag = false; saveFlag = false;
} }
return saveFlag; return saveFlag;
} }
public static ChatCache loadChatCache(String chatKey, ServletContext context, UserInfo userInfo, Boolean loadCacheStatus) throws Exception { public static synchronized ChatCache loadChatCache(String chatKey, ServletContext context, UserInfo userInfo, Boolean loadCacheStatus) throws Exception {
ChatCache chatCache = null; ChatCache chatCache = null;
GameEnv gameEnv = null; GameEnv gameEnv = null;
Map<String ,String> infoPoint = null; Map<String ,String> infoPoint = null;
...@@ -171,7 +108,12 @@ public class ChatCacheController { ...@@ -171,7 +108,12 @@ public class ChatCacheController {
/**
* 通过chat_key获得后台保存的历史信息点
* chatCache:存储了chatKye相对应的对话记录(历史信息点)
*
* @return 历史信息点,对话过程中引擎提取的用户信息
*/
public static synchronized ChatCache getChatCache(String chatKey, ServletContext context, UserInfo userinfo, Map<String, String[]> receiveParamters, Boolean loadCacheStatus) throws Exception { public static synchronized ChatCache getChatCache(String chatKey, ServletContext context, UserInfo userinfo, Map<String, String[]> receiveParamters, Boolean loadCacheStatus) throws Exception {
Map<String, ChatCache> chatCacheMap = null; Map<String, ChatCache> chatCacheMap = null;
ChatCache chatCache = null; ChatCache chatCache = null;
...@@ -200,16 +142,22 @@ public class ChatCacheController { ...@@ -200,16 +142,22 @@ public class ChatCacheController {
HashSet<String> restartKeySet = new HashSet<String>(){ HashSet<String> restartKeySet = new HashSet<String>(){
{ {
add("重新开始"); add("重新开始");
add("新游戏");
} }
}; };
//如果用户之前没有玩过或者有一段时间没有玩
if(chatCache == null){ if(chatCache == null){
//识别到的语义关系包含start_options
if(receiveParamters.containsKey("start_options")){ if(receiveParamters.containsKey("start_options")){
String startKeyword = receiveParamters.get("start_options")[0].split(":", 2)[1]; String startKeyword = receiveParamters.get("start_options")[0].split(":", 2)[1];
//有继续游戏相关的关键词
if(startKeySet.contains(startKeyword)) { if(startKeySet.contains(startKeyword)) {
//加载存档
chatCache = loadChatCache(chatKey, context, userinfo, loadCacheStatus); chatCache = loadChatCache(chatKey, context, userinfo, loadCacheStatus);
//没有继续游戏相关的关键词
}else { }else {
chatCache = new ChatCache(userinfo); chatCache = new ChatCache(userinfo);
} }
...@@ -217,8 +165,11 @@ public class ChatCacheController { ...@@ -217,8 +165,11 @@ public class ChatCacheController {
chatCache = new ChatCache(userinfo); chatCache = new ChatCache(userinfo);
} }
chatCacheMap.put(chatKey, chatCache); chatCacheMap.put(chatKey, chatCache);
//用户几分钟前还在玩
} else { } else {
//将重新加载的标识重置
chatCache.setReloading(false); chatCache.setReloading(false);
//识别到的语义关系包含start_options
if(receiveParamters.containsKey("start_options")){ if(receiveParamters.containsKey("start_options")){
String startKeyword = receiveParamters.get("start_options")[0].split(":", 2)[1]; String startKeyword = receiveParamters.get("start_options")[0].split(":", 2)[1];
if(startKeySet.contains(startKeyword)) { if(startKeySet.contains(startKeyword)) {
...@@ -242,7 +193,7 @@ public class ChatCacheController { ...@@ -242,7 +193,7 @@ public class ChatCacheController {
/** /**
* chatChche中每个chatkey都有对应的最后更新时间,如果最后更新时间已经是x分钟前(超时),就清除该chatKey的数据 * chatChche中每个chatkey都有对应的最后更新时间,如果最后更新时间已经是x分钟前(超时),就清除该chatKey的数据
*/ */
public static synchronized void updateChatCache4Delete(String curChatKey, ServletContext context) throws IOException { public static synchronized void updateChatCache4Delete(String curChatKey, ServletContext context, UserInfo userInfo) throws IOException {
String chatKey; String chatKey;
ChatCache chatCache = null; ChatCache chatCache = null;
long lastChatTime, now; long lastChatTime, now;
...@@ -273,7 +224,7 @@ public class ChatCacheController { ...@@ -273,7 +224,7 @@ public class ChatCacheController {
/** /**
* 根据chatKey更新chatCache的数据,并修改最后更新时间 * 根据chatKey更新chatCache的数据,并修改最后更新时间
*/ */
public static synchronized void updateChatCache4Insert(Map<String, String> curInfoPoint, Map<String, String> historyInfoPoint, GameEnv gameEnv, ServletContext context) { public static synchronized void updateChatCache4Insert(Map<String, String> curInfoPoint, Map<String, String> historyInfoPoint, GameEnv gameEnv, ServletContext context, UserInfo userInfo) {
historyInfoPoint.put("lastUpdateTime", String.valueOf(System.currentTimeMillis())); historyInfoPoint.put("lastUpdateTime", String.valueOf(System.currentTimeMillis()));
Map<String, ChatCache> keyCacheMap = (Map<String, ChatCache>) context.getAttribute("chatCache"); Map<String, ChatCache> keyCacheMap = (Map<String, ChatCache>) context.getAttribute("chatCache");
ChatCache chatCache = keyCacheMap.get(curInfoPoint.get("chat_key")); ChatCache chatCache = keyCacheMap.get(curInfoPoint.get("chat_key"));
...@@ -283,7 +234,7 @@ public class ChatCacheController { ...@@ -283,7 +234,7 @@ public class ChatCacheController {
} }
public static synchronized boolean findChatCache(String chatKey, ServletContext context) throws Exception { public static synchronized boolean findChatCache(String chatKey, ServletContext context, String botAccount) throws Exception {
ChatCache chatCache = null; ChatCache chatCache = null;
GameEnv gameEnv = null; GameEnv gameEnv = null;
Map<String ,String> infoPoint = null; Map<String ,String> infoPoint = null;
...@@ -310,6 +261,8 @@ public class ChatCacheController { ...@@ -310,6 +261,8 @@ public class ChatCacheController {
return false; return false;
} }
public static synchronized boolean deleteUnuseChatCache(String chatKey, ServletContext context) throws Exception { public static synchronized boolean deleteUnuseChatCache(String chatKey, ServletContext context) throws Exception {
try { try {
System.out.println("移除----------------------------"); System.out.println("移除----------------------------");
......
...@@ -186,12 +186,16 @@ public class ConditionTableController { ...@@ -186,12 +186,16 @@ public class ConditionTableController {
public static String writeConfigText(String userName, UserInfo userinfo) throws IOException { public static String writeConfigText(String userName, UserInfo userinfo) throws IOException {
System.out.println("p");
System.out.println(userName);
String CONFIG_DIR = System.getProperty("user.dir") + "/config", configText; String CONFIG_DIR = System.getProperty("user.dir") + "/config", configText;
String path = CONFIG_DIR + "/" + userName + ".txt"; String path = CONFIG_DIR + "/" + userName + ".txt";
File file = new File(path); File file = new File(path);
File dir = new File(System.getProperty("user.dir") + "/config"); File dir = new File(System.getProperty("user.dir") + "/config");
System.out.println(userName);
System.out.println("config_dir" + dir.getAbsolutePath());
String returnMessage = "success"; String returnMessage = "success";
if (!dir.exists()) if (!dir.exists())
......
...@@ -18,7 +18,7 @@ public class FormsPoster { ...@@ -18,7 +18,7 @@ public class FormsPoster {
LogWriter logWriter = null; LogWriter logWriter = null;
public static String QA_URL = "http://aliyun-hz1.chewrobot.com:58000/game"; public static String QA_URL = "http://qcloud-gz1.chewrobot.com:58000/game";
public FormsPoster(LogWriter logWriter) { public FormsPoster(LogWriter logWriter) {
this.logWriter = logWriter; this.logWriter = logWriter;
......
...@@ -110,7 +110,9 @@ public class MyFunc { ...@@ -110,7 +110,9 @@ public class MyFunc {
return true; return true;
} }
public static JSONObject postJSON(String url, JSONObject data, String auth) throws UnsupportedEncodingException {
public static JSONObject postJSON(String url, JSON data, String auth) throws UnsupportedEncodingException {
JSONObject jobj = new JSONObject(); JSONObject jobj = new JSONObject();
......
...@@ -841,149 +841,6 @@ public class QuestionMatcher { ...@@ -841,149 +841,6 @@ public class QuestionMatcher {
} }
public void updateKnowledge(Condition condition) throws ParseException {
String keyword, variableName, updateValue, returnStr = "1";
Iterator<String> iit = condition.updateKnowledge.keySet().iterator();
while (iit.hasNext()) {
variableName = iit.next();
updateValue = condition.updateKnowledge.get(variableName);
keyword = historyInfoPoint.get(variableName);
//如果变量名开头为NPC或者item,就专门交给world处理
if((userinfo.varInitialMap.get("botType") != null && userinfo.varInitialMap.get("botType").equals("game")) &&
(variableName.startsWith("npc_") || variableName.startsWith("goods_") || variableName.startsWith("map_") || variableName.startsWith("place_"))){
try {
returnStr = worldController.worldOperation(gameEnv, variableName, updateValue, curInfoPoint, historyInfoPoint);
updateValue = returnStr;
}catch (Exception e){
e.printStackTrace();
updateValue = "游戏模块处理出错";
}
}else {
try {
//做数字加法
if (updateValue.startsWith("+")) {
if (keyword == null || keyword.equals(""))
keyword = "0";
if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) {
long time = MyFunc.transferToMillisecond(keyword);
int offset = Integer.parseInt(updateValue.substring(1));
updateValue = MyFunc.transferToStandardTime(time + (1000 * offset));
} else if (StringUtils.isNumeric(keyword)) {
int number = Integer.parseInt(keyword);
int offset = Integer.parseInt(updateValue.substring(1));
updateValue = String.valueOf(number + offset);
}
//做数字减法
} else if (updateValue.startsWith("-")) {
if (keyword == null || keyword.equals(""))
keyword = "0";
if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) {
long time = MyFunc.transferToMillisecond(keyword);
int offset = Integer.parseInt(updateValue.substring(1));
updateValue = MyFunc.transferToStandardTime(time - (1000 * offset));
} else if (StringUtils.isNumeric(keyword)) {
int number = Integer.parseInt(keyword);
int offset = Integer.parseInt(updateValue.substring(1));
updateValue = String.valueOf(number - offset);
}
//做字符串累加
} else if (updateValue.startsWith("str+")) {
if (keyword == null || keyword.equals(""))
keyword = "";
updateValue = keyword + updateValue.substring(4);
//做字符串删除
} else if (updateValue.startsWith("str-")) {
if (keyword == null || keyword.equals(""))
keyword = "";
updateValue = keyword.replace(updateValue.substring(4), "");
} else if (updateValue.startsWith("int+=")) {
if (keyword == null || keyword.equals(""))
keyword = "0";
if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) {
long time = MyFunc.transferToMillisecond(keyword);
int offset = Integer.parseInt(updateValue.substring(1));
updateValue = MyFunc.transferToStandardTime(time + (1000 * offset));
} else if (StringUtils.isNumeric(keyword)) {
int number = Integer.parseInt(keyword);
int offset = Integer.parseInt(updateValue.substring(5));
updateValue = String.valueOf(number + offset);
}
//做数字减法
} else if (updateValue.startsWith("int-=")) {
if (keyword == null || keyword.equals(""))
keyword = "0";
if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) {
long time = MyFunc.transferToMillisecond(keyword);
int offset = Integer.parseInt(updateValue.substring(5));
updateValue = MyFunc.transferToStandardTime(time - (1000 * offset));
} else if (StringUtils.isNumeric(keyword)) {
int number = Integer.parseInt(keyword);
int offset = Integer.parseInt(updateValue.substring(1));
updateValue = String.valueOf(number - offset);
}
//做字符串累加
} else if (updateValue.startsWith("str+=")) {
if (keyword == null || keyword.equals(""))
keyword = "";
updateValue = keyword + updateValue.substring(5);
//做字符串删除
} else if (updateValue.startsWith("str-=")) {
if (keyword == null || keyword.equals(""))
keyword = "";
updateValue = keyword.replace(updateValue.substring(5), "");
} else if (updateValue.startsWith("var=")) {
String conditionName = updateValue.substring(5, updateValue.length() - 3);
if (updateValue.endsWith("-1}")) {
if (curInfoPoint.get(conditionName) != null) {
updateValue = curInfoPoint.get(conditionName);
} else {
updateValue = "";
}
} else if (updateValue.endsWith("-2}")) {
if (historyInfoPoint.get(conditionName) != null) {
updateValue = historyInfoPoint.get(conditionName);
} else {
updateValue = "";
}
} else if (updateValue.endsWith("nextStep-3}")) {
updateValue = condition.nextStep;
} else if (updateValue.endsWith("reply-3}")) {
updateValue = MyFunc.randStr(condition.answer);
}
if (variableName.startsWith("process-nextStep")) {
condition.nextStep = updateValue;
updateValue = "";
}
}
} catch (Exception e) {
e.printStackTrace();
continue;
}
}
if(updateValue.equals("")) {
curInfoPoint.put(variableName + "_backup", curInfoPoint.get(variableName)); //更新答案将某变量设为空时,要将当前信息点也清空,不然后边信息点转移时这个变量的已知信息依然不是空的。
// 为了避免将当前信息点清空后debug信息显示不完整,现创造一个备份,在appendDebugInfo后会将这个备份清空。
curInfoPoint.put(variableName, "");
}
historyInfoPoint.put(variableName, updateValue);
}
}
public void updateKnowledge2(Condition condition) throws ParseException { public void updateKnowledge2(Condition condition) throws ParseException {
String keyword, variableName, updateValue, returnStr = "1"; String keyword, variableName, updateValue, returnStr = "1";
...@@ -1118,7 +975,6 @@ public class QuestionMatcher { ...@@ -1118,7 +975,6 @@ public class QuestionMatcher {
} }
} }
......
...@@ -160,7 +160,7 @@ public class ResponseFilter { ...@@ -160,7 +160,7 @@ public class ResponseFilter {
npc = m.group(1); npc = m.group(1);
location = worldController.worldOperation(gameEnv, "npc_query", "queryLocationByNPCName:" + npc, curInfoPoint, historyInfoPoint); location = worldController.worldOperation(gameEnv, "npc_query", "queryLocationByNPCName:" + npc, curInfoPoint, historyInfoPoint);
if (location.equals(site) || location.equals("无处不在") || location.equals("任意地点")){ if (location.equals(site) || location.equals("无处不在") || location.equals("任意地点")){
if(gameEnv.queryNpcAttrByNpcName(npc, "能否说话").equals("能")){ if(gameEnv.queryNpcAttrByNpcName(npc, "能否说话") == null || gameEnv.queryNpcAttrByNpcName(npc, "能否说话").equals("能")){
flag = 1; flag = 1;
logWriter.record("\"" + reply + "\":匹配", 1); logWriter.record("\"" + reply + "\":匹配", 1);
}else { }else {
......
...@@ -12,7 +12,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -12,7 +12,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
@WebServlet(name = "FindCacheServlet", urlPatterns = {"/findCache"}) @WebServlet(name = "FindCacheServlet", urlPatterns = {"/findChatCache"})
public class FindCacheServlet extends HttpServlet { public class FindCacheServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ServletContext context = this.getServletContext(); ServletContext context = this.getServletContext();
...@@ -20,16 +20,18 @@ public class FindCacheServlet extends HttpServlet { ...@@ -20,16 +20,18 @@ public class FindCacheServlet extends HttpServlet {
request.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8");
String chatKey = request.getParameter("client_id"); String chatKey = request.getParameter("client_id");
String botAccount = request.getParameter("aipioneer_username");
Boolean exist = false; Boolean exist = false;
try { try {
exist = ChatCacheController.findChatCache(chatKey, context); exist = ChatCacheController.findChatCache(chatKey+ "-" + botAccount, context, botAccount);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
JSONObject responseJSONObject = new JSONObject(); JSONObject responseJSONObject = new JSONObject();
responseJSONObject.put("exist", exist); responseJSONObject.put("exist", exist);
responseJSONObject.put("aipioneer_username", botAccount);
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8"); response.setContentType("application/json; charset=utf-8");
response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Origin", "*");
......
...@@ -142,12 +142,12 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -142,12 +142,12 @@ public class GetAnswerServlet extends HttpServlet {
matcher.infoTransfer(bestMatch, context, debugFlag); matcher.infoTransfer(bestMatch, context, debugFlag);
ChatCacheController.updateChatCache4Insert(curInfoPoint, historyInfoPoint, chatCache.getGameEnv(), context); ChatCacheController.updateChatCache4Insert(curInfoPoint, historyInfoPoint, chatCache.getGameEnv(), context, userinfo);
//清理超时的用户数据 //清理超时的用户数据
if (context.getAttribute("cacheUpdateTime") == null) if (context.getAttribute("cacheUpdateTime") == null)
context.setAttribute("cacheUpdateTime", System.currentTimeMillis()); context.setAttribute("cacheUpdateTime", System.currentTimeMillis());
if (System.currentTimeMillis() - (long) context.getAttribute("cacheUpdateTime") > ChatCacheController.TIME_OUT) { if (System.currentTimeMillis() - (long) context.getAttribute("cacheUpdateTime") > ChatCacheController.TIME_OUT) {
ChatCacheController.updateChatCache4Delete(chatKey, context); ChatCacheController.updateChatCache4Delete(chatKey, context, userinfo);
context.setAttribute("cacheUpdateTime", System.currentTimeMillis()); context.setAttribute("cacheUpdateTime", System.currentTimeMillis());
} }
......
package com.qiwu.chatbotbackend.servlet; package com.qiwu.chatbotbackend.servlet;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.entity.ChatCache; import com.qiwu.chatbotbackend.entity.ChatCache;
import com.qiwu.chatbotbackend.processing.ChatCacheController; import com.qiwu.chatbotbackend.processing.ChatCacheController;
...@@ -11,28 +13,50 @@ import javax.servlet.http.HttpServletRequest; ...@@ -11,28 +13,50 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Map; import java.util.Map;
@WebServlet(name = "SaveChatCacheServlet", urlPatterns = {"/saveChatCache"}) @WebServlet(name = "SaveChatCacheServlet", urlPatterns = {"/saveChatCache"})
public class SaveChatCacheServlet extends HttpServlet { public class SaveChatCacheServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8");
String chatKey = request.getParameter("chat_key"), message = ""; String chatKey = request.getParameter("chatKey"), message = "";
OutputStream out = response.getOutputStream();
ServletContext context = this.getServletContext(); ServletContext context = this.getServletContext();
chatKey = chatKey.split("@")[0];
Boolean flag = false;
Map<String, ChatCache> chatCacheMap = (Map<String, ChatCache>)context.getAttribute("chatCache"); Map<String, ChatCache> chatCacheMap = (Map<String, ChatCache>)context.getAttribute("chatCache");
ChatCache chatCache = chatCacheMap.get(chatKey); ChatCache chatCache = chatCacheMap.get(chatKey);
//message = ChatCacheController.saveChatCache(chatKey, context);
if(chatCache != null) {
flag = ChatCacheController.saveChatCache(chatKey, chatCache);
chatCacheMap.remove(chatKey);
}
System.out.println("调用接口删除" + chatKey);
//out.write(message.getBytes()); //out.write(message.getBytes());
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
PrintWriter out = response.getWriter();
JSONObject retData = new JSONObject();
retData.put("status", flag);
System.out.println("xx:" + retData.toJSONString());
out.append(retData.toJSONString());
out.flush(); out.flush();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
} }
} }
......
...@@ -120,7 +120,7 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -120,7 +120,7 @@ public class GameBotUtil extends BasicBotUtil{
keyword = gameEnv.queryGoodsAttrByGoodsName(nameSeries[2], nameSeries[3]); keyword = gameEnv.queryGoodsAttrByGoodsName(nameSeries[2], nameSeries[3]);
System.out.println("return" + keyword); System.out.println("return" + keyword);
}else if (nameSeries.length == 3){ }else if (nameSeries.length == 3){
keyword = gameEnv.queryNpcAttrByNpcName(nameSeries[1], nameSeries[2]); keyword = gameEnv.queryGoodsAttrByGoodsName(nameSeries[1], nameSeries[2]);
} }
}else if(actionName.startsWith("isNeighbour")){ }else if(actionName.startsWith("isNeighbour")){
...@@ -146,6 +146,9 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -146,6 +146,9 @@ public class GameBotUtil extends BasicBotUtil{
} }
if(keyword == null)
keyword = "";
return keyword; return keyword;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment