Commit 7648340e by hxw

激活优先级默认会加一,剧情生成的分支中数据reply、unknownText、等放到原来的剧情中

parent fdca5a9f
package com.qiwu.chatbotbackend.entity;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
/**
* 保存配置文件每一行(单行)解析后的信息的实体类。
* 独立于引擎的另一种condition
*/
public class Action {
public int priority = -1;
public int activePriority = 0; //如果本condition被其他condition激活
public int auxiliaryPriority = 0; //用于priority一样时人为设置的辅助优先级
public HashSet<String> keywordSet = new HashSet<String>();
public HashMap<String, HashSet<String>> historyPremise = new HashMap<String, HashSet<String>>();
public HashMap<String, HashSet<String>> currentPremise = new HashMap<String, HashSet<String>>();
public HashMap<String, String> updateKnowledge = new LinkedHashMap<String, String>();
public String[] answer = {"",};
public String nextStep = "";
public HashMap<String, String> featureMap = new HashMap<String, String>();
public String indexName = "";
public int id = 0;
public String configName = "";
public String status = "waiting";
//public ArrayList<String> indexName = new ArrayList<String>();
public Action(int priority) {
this.priority = priority;
this.activePriority = priority;
}
/**
*
* @param originAction 这个action的初始状态
* @param basePriority 激活originAction的action的条件数量
* @param baseAuxiliaryPriority 激活originAction的action的辅助优先级
*/
public Action(Action originAction, int basePriority, int baseAuxiliaryPriority) {
this.priority = originAction.priority;
this.keywordSet = originAction.keywordSet;
this.historyPremise = originAction.historyPremise;
this.currentPremise = originAction.currentPremise;
this.answer = originAction.answer;
this.nextStep = originAction.nextStep;
this.featureMap = originAction.featureMap;
this.updateKnowledge = originAction.updateKnowledge;
this.indexName = originAction.indexName;
this.id = originAction.id;
this.configName = originAction.configName;
this.status = originAction.status;
this.activePriority = originAction.activePriority + basePriority + 1; //激活会多一个优先级
//如果激活originAction的action,它的辅助优先级高于originAction,那么。。
if(baseAuxiliaryPriority > originAction.auxiliaryPriority)
this.auxiliaryPriority = baseAuxiliaryPriority;
else
this.auxiliaryPriority = originAction.auxiliaryPriority;
}
public Action() {
}
}
...@@ -8,7 +8,7 @@ import java.util.List; ...@@ -8,7 +8,7 @@ import java.util.List;
*/ */
public class UserInfo { public class UserInfo {
public UserInfo(String botAccount) { public UserInfo(String botAccount) {
this.conditionTable = new HashMap<String, List<Condition>>(); this.conditionTable = new HashMap<String, List<Action>>();
this.configStr = ""; this.configStr = "";
this.botAccount = botAccount; this.botAccount = botAccount;
this.extraInfo = new HashMap<String, String>() { this.extraInfo = new HashMap<String, String>() {
...@@ -17,18 +17,18 @@ public class UserInfo { ...@@ -17,18 +17,18 @@ public class UserInfo {
} }
}; };
this.id2config = new HashMap<Integer, String>(); this.id2config = new HashMap<Integer, String>();
this.id2condition = new HashMap<Integer, Condition>(); this.id2condition = new HashMap<Integer, Action>();
this.varInitialMap = new HashMap<String, String>(); this.varInitialMap = new HashMap<String, String>();
this.name2condition = new HashMap<String, Condition>(); this.name2condition = new HashMap<String, Action>();
} }
public HashMap<String, List<Condition>> conditionTable; public HashMap<String, List<Action>> conditionTable;
public String configStr; public String configStr;
public String botAccount; public String botAccount;
public HashMap<String, String> extraInfo; public HashMap<String, String> extraInfo;
public HashMap<Integer, String> id2config; public HashMap<Integer, String> id2config;
public HashMap<Integer, Condition> id2condition; public HashMap<Integer, Action> id2condition;
public HashMap<String, Condition> name2condition; public HashMap<String, Action> name2condition;
//存储需要初始化的变量 //存储需要初始化的变量
public HashMap<String, String> varInitialMap; public HashMap<String, String> varInitialMap;
......
...@@ -3,7 +3,7 @@ package com.qiwu.chatbotbackend.gameDesign; ...@@ -3,7 +3,7 @@ package com.qiwu.chatbotbackend.gameDesign;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.JConfig; import com.qiwu.chatbotbackend.entity.ConfigTerm;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import java.util.*; import java.util.*;
...@@ -128,66 +128,66 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -128,66 +128,66 @@ public class CharacterConstructor extends ElementConstructor {
//根据根据NPC的名字查询地点 //根据根据NPC的名字查询地点
for (String conditionName : locationRelateConditions) { for (String conditionName : locationRelateConditions) {
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ", conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ",
"match,return-0", "", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName "match,return-0", "", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "npc"); ConfigTerm.activateCopy(configTerm, configTermList, "npc");
//zainali 和wenzainali 都识别到时优先匹配wenzainali //zainali 和wenzainali 都识别到时优先匹配wenzainali
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName) + "," + conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName) + "," +
"zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ", "zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ",
"match,return-0", "", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName "match,return-0", "", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "npc"); ConfigTerm.activateCopy(configTerm, configTermList, "npc");
//jConfigList.add(jConfig); //configTermList.add(configTerm);
} }
//根据根据NPC名字和属性查询属性值 //根据根据NPC名字和属性查询属性值
for(String conditionName: attrRelateConditions){ for(String conditionName: attrRelateConditions){
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ", conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ",
"match,return-0", "", "yaobuyao", "match,return-0", "", "yaobuyao",
"npc_query:queryAttrByNPCName:" + conditionName "npc_query:queryAttrByNPCName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "npc"); ConfigTerm.activateCopy(configTerm, configTermList, "npc");
} }
//根据根据NPC类别和地点属性查询所有NPC实例 //根据根据NPC类别和地点属性查询所有NPC实例
for (String conditionName : classRelateConditions) { for (String conditionName : classRelateConditions) {
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ", conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ",
"match,return-0", "", "yaobuyao", "match,return-0", "", "yaobuyao",
"npc_query:queryAroundNpcByClassName:" + conditionName "npc_query:queryAroundNpcByClassName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "npc"); ConfigTerm.activateCopy(configTerm, configTermList, "npc");
//jConfigList.add(jConfig); //configTermList.add(configTerm);
} }
//根据类名查询周围所有实例 //根据类名查询周围所有实例
for (String conditionName : findRelateConditions) { for (String conditionName : findRelateConditions) {
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName).toString(), " ", conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName).toString(), " ",
"match,return-0", "match,return-0",
"", "",
" ", " ",
"npc_query:queryFindNPCWay:" + conditionName "npc_query:queryFindNPCWay:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "npc"); ConfigTerm.activateCopy(configTerm, configTermList, "npc");
} }
//查询说话的人 //查询说话的人
for (String conditionName : talkerRelateConditions) { for (String conditionName : talkerRelateConditions) {
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + keywordMap.get("talker_" + conditionName).toString().replace("botname", botName), " ", conditionName + "::match-Include=" + keywordMap.get("talker_" + conditionName).toString().replace("botname", botName), " ",
"match,return-0", "match,return-0",
"", "",
" ", " ",
"npc_query:queryLastTalker:" "npc_query:queryLastTalker:"
); );
JConfig.activateCopy(jConfig, jConfigList, "npc"); ConfigTerm.activateCopy(configTerm, configTermList, "npc");
} }
......
...@@ -3,7 +3,7 @@ package com.qiwu.chatbotbackend.gameDesign; ...@@ -3,7 +3,7 @@ package com.qiwu.chatbotbackend.gameDesign;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.JConfig; import com.qiwu.chatbotbackend.entity.ConfigTerm;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import java.util.*; import java.util.*;
...@@ -19,7 +19,7 @@ public class ElementConstructor { ...@@ -19,7 +19,7 @@ public class ElementConstructor {
Map<String, StringBuffer> keywordMap = null; Map<String, StringBuffer> keywordMap = null;
SqlHelper helper = null; SqlHelper helper = null;
HashSet<String> exceptRelation = null; HashSet<String> exceptRelation = null;
JConfig jConfig = null; ConfigTerm configTerm = null;
String CHITCHAT_URL = "http:192.168.1.178:1111/test"; String CHITCHAT_URL = "http:192.168.1.178:1111/test";
String botAccount; String botAccount;
...@@ -29,7 +29,7 @@ public class ElementConstructor { ...@@ -29,7 +29,7 @@ public class ElementConstructor {
List<JSONObject> configDataList = new ArrayList<JSONObject>(); List<JSONObject> configDataList = new ArrayList<JSONObject>();
List<JConfig> jConfigList = new ArrayList<JConfig>(); List<ConfigTerm> configTermList = new ArrayList<ConfigTerm>();
StringBuffer configText = new StringBuffer(); StringBuffer configText = new StringBuffer();
Map<String, String> varInitialMap = new HashMap<String, String>(); Map<String, String> varInitialMap = new HashMap<String, String>();
Map<String, String> conditionDescription = new HashMap<String, String>(); Map<String, String> conditionDescription = new HashMap<String, String>();
...@@ -46,8 +46,8 @@ public class ElementConstructor { ...@@ -46,8 +46,8 @@ public class ElementConstructor {
public void construct(JSONObject gameElements, UserInfo userinfo) { } public void construct(JSONObject gameElements, UserInfo userinfo) { }
public List<JConfig> getjConfigList() { public List<ConfigTerm> getConfigTermList() {
return jConfigList; return configTermList;
} }
public Map<String, String> getConditionDescription() { public Map<String, String> getConditionDescription() {
...@@ -69,12 +69,12 @@ public class ElementConstructor { ...@@ -69,12 +69,12 @@ public class ElementConstructor {
public void generateConfigText(List<Integer> idList) { public void generateConfigText(List<Integer> idList) {
int id, length = idList.size(); int id, length = idList.size();
String varValue; String varValue;
JConfig jConfig = null; ConfigTerm configTerm = null;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
jConfig = jConfigList.get(i); configTerm = configTermList.get(i);
id = idList.get(i); id = idList.get(i);
configText.append(jConfig.toString() + id + "\n"); configText.append(configTerm.toString() + id + "\n");
} }
for (String varName : varInitialMap.keySet()) { for (String varName : varInitialMap.keySet()) {
varValue = varInitialMap.get(varName); varValue = varInitialMap.get(varName);
......
...@@ -3,7 +3,7 @@ package com.qiwu.chatbotbackend.gameDesign; ...@@ -3,7 +3,7 @@ package com.qiwu.chatbotbackend.gameDesign;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.JConfig; import com.qiwu.chatbotbackend.entity.ConfigTerm;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import java.util.*; import java.util.*;
...@@ -109,7 +109,7 @@ public class ItemConstructor extends ElementConstructor { ...@@ -109,7 +109,7 @@ public class ItemConstructor extends ElementConstructor {
//与地点查询相关的condition //与地点查询相关的condition
for(String conditionName: locationRelateConditions){ for(String conditionName: locationRelateConditions){
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString() + "," + conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString() + "," +
"zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ", "zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ",
"match,return-0", "match,return-0",
...@@ -117,65 +117,65 @@ public class ItemConstructor extends ElementConstructor { ...@@ -117,65 +117,65 @@ public class ItemConstructor extends ElementConstructor {
" ", " ",
"goods_query:queryLocationByConditionName:" + conditionName "goods_query:queryLocationByConditionName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "item"); ConfigTerm.activateCopy(configTerm, configTermList, "item");
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ", conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0", "match,return-0",
"", "",
" ", " ",
"goods_query:queryLocationByConditionName:" + conditionName "goods_query:queryLocationByConditionName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "item"); ConfigTerm.activateCopy(configTerm, configTermList, "item");
} }
//根据根据物品名字和属性查询属性值 //根据根据物品名字和属性查询属性值
for (String conditionName : attrRelateConditions) { for (String conditionName : attrRelateConditions) {
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ", conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0", "match,return-0",
"", "",
" ", " ",
"goods_query:queryAttrByGoodsName:" + conditionName "goods_query:queryAttrByGoodsName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "item"); ConfigTerm.activateCopy(configTerm, configTermList, "item");
} }
//根据类名查询周围所有实例 //根据类名查询周围所有实例
for (String conditionName : attrRelateConditions) { for (String conditionName : attrRelateConditions) {
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + classKeywords, " ", conditionName + "::match-Include=" + classKeywords, " ",
"match,return-0", "match,return-0",
"", "",
" ", " ",
"goods_query:queryAroundGoodsByClassName:" + conditionName "goods_query:queryAroundGoodsByClassName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "item"); ConfigTerm.activateCopy(configTerm, configTermList, "item");
} }
//根据类名查询周围所有实例 //根据类名查询周围所有实例
for (String conditionName : ownRelateConditions) { for (String conditionName : ownRelateConditions) {
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ", conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0", "match,return-0",
"", "",
" ", " ",
"goods_query:queryPlayerItems:" + conditionName "goods_query:queryPlayerItems:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "item"); ConfigTerm.activateCopy(configTerm, configTermList, "item");
} }
//根据类名查询周围所有实例 //根据类名查询周围所有实例
for (String conditionName : findRelateConditions) { for (String conditionName : findRelateConditions) {
jConfig = new JConfig( configTerm = new ConfigTerm(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ", conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0", "match,return-0",
"", "",
" ", " ",
"goods_query:queryFindItemWay:" + conditionName "goods_query:queryFindItemWay:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "item"); ConfigTerm.activateCopy(configTerm, configTermList, "item");
} }
} catch(Exception e){ } catch(Exception e){
......
package com.qiwu.chatbotbackend.gameDesign;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.ConfigTerm;
import com.qiwu.chatbotbackend.entity.UserInfo;
import java.util.*;
import static com.qiwu.chatbotbackend.gameDesign.PlotConstructor2.*;
public class ListeningConstructor extends ElementConstructor{
public ListeningConstructor(SqlHelper helper, int botId, String botAccount, Map<String, StringBuffer> keywordMap, HashSet<String> exceptRelation, StringBuffer POS) {
super();
this.helper = helper;
this.botId = botId;
this.botAccount = botAccount;
this.exceptRelation = exceptRelation;
this.keywordMap = keywordMap;
this.POS = POS;
}
public void construct(JSONObject jsonObject, UserInfo userinfo) {
}
public static void cc(String botAccount, JSONObject gameELments, HashMap<String, JSONObject> plotIndex, List<ConfigTerm> configTermList){
int size = 0;
String feature, nextPlotId, reply = "", nextCondition = "", nextLocation = "", priority;
String nTaskLineName, lastTaskCondition, lastTaskReply, nextGameStep;
Boolean autoJump = false;
List<String> curPremiseList = new ArrayList<String>();
List<String> hisPremiseList = new ArrayList<String>();
JSONArray listeningActions = gameELments.getJSONArray("listeningActions");
JSONObject plotNode = null;
size = listeningActions.size();
JSONObject config = null;
for(int i = 0; i < size;i++){
plotNode = null;
autoJump = false;
priority = "1";
feature = "match";
config = listeningActions.getJSONObject(i);
curPremiseList = JSONArray.parseArray(config.getJSONArray("curPremise").toJSONString(), String.class);
hisPremiseList = JSONArray.parseArray(config.getJSONArray("hisPremise").toJSONString(), String.class);
Map<String, String> updateKnowledge = JSONObject.parseObject(config.getJSONObject("updateKnowledge").toJSONString(), Map.class);
nextPlotId = config.getString("nextPlotId");
if(nextPlotId != null){
plotNode = plotIndex.get(nextPlotId);
}
if(plotNode != null){
reply = plotNode.getString("plotText");
nextCondition = plotNode.getString("conditionName");
nextLocation = plotNode.getString("place");
autoJump = plotNode.getBoolean("autoJump");
if(nextCondition == null || nextCondition.equals("")){
nextCondition = "yaobuyao";
}
if(autoJump){
feature = "match,activate:after";
updateKnowledge.put("plot_jump_text", "str+" + reply);
nextCondition = "plot_" + nextPlotId + "_*";
reply = "";
}else{
feature = "match";
}
if(plotNode.getString("priority") != null)
priority = plotNode.getString("priority");
updateKnowledge.put(nextPlotId + "_from", "");
updateKnowledge.put("site", nextLocation);
nTaskLineName = String.format(TASK_LINE, nextLocation);
//任务线最后一个condition
lastTaskCondition = String.format(TASK_CONDITION, nextLocation);
lastTaskReply = String.format(TASK_REPLY, nextLocation);
nextGameStep = String.format(GAME_STEP_FORMAT, botAccount,nextPlotId);
updateKnowledge.put(lastTaskCondition, nextCondition);
updateKnowledge.put(lastTaskReply, reply);
updateKnowledge.put(nextPlotId, "1"); //下一步设为1
updateKnowledge.put(nTaskLineName, nextGameStep);
}else{
feature = "match,return-0";
}
ConfigTerm configTerm = new ConfigTerm(
curPremiseList,
hisPremiseList,
updateKnowledge,
"", "", "", feature, reply, nextCondition, priority
);
System.out.println("生成:" + curPremiseList.get(0));
configTermList.add(configTerm);
}
}
}
...@@ -90,7 +90,7 @@ public class ChatCacheController { ...@@ -90,7 +90,7 @@ public class ChatCacheController {
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 nowTime = now .format(format); String nowTime = now .format(format);
Boolean opFlag; Boolean opFlag, destroy = false;
System.out.println("游戏存档中"); System.out.println("游戏存档中");
...@@ -102,6 +102,7 @@ public class ChatCacheController { ...@@ -102,6 +102,7 @@ public class ChatCacheController {
if(helper == null){ if(helper == null){
helper = new SqlHelper(); helper = new SqlHelper();
destroy = true;
} }
File dir = new File(CHAT_CACHE_DIR); File dir = new File(CHAT_CACHE_DIR);
...@@ -125,6 +126,9 @@ public class ChatCacheController { ...@@ -125,6 +126,9 @@ public class ChatCacheController {
opFlag = helper.insertArchiveInfo(archiveName, userKey, site); opFlag = helper.insertArchiveInfo(archiveName, userKey, site);
if(destroy)
helper.destroy();
} catch (Exception e) { } catch (Exception e) {
System.out.println("游戏存档时发生异常"); System.out.println("游戏存档时发生异常");
e.printStackTrace(); e.printStackTrace();
...@@ -140,6 +144,7 @@ public class ChatCacheController { ...@@ -140,6 +144,7 @@ public class ChatCacheController {
ChatCache chatCache = null; ChatCache chatCache = null;
GameEnv gameEnv = null; GameEnv gameEnv = null;
Map<String ,String> infoPoint = null; Map<String ,String> infoPoint = null;
System.out.println(archiveInfo.getArchiveId());
String keys[] = archiveInfo.getArchiveId().split(COMBINE_PUNC1); String keys[] = archiveInfo.getArchiveId().split(COMBINE_PUNC1);
keys[1] = keys[1].split("-")[0]; keys[1] = keys[1].split("-")[0];
...@@ -196,7 +201,7 @@ public class ChatCacheController { ...@@ -196,7 +201,7 @@ public class ChatCacheController {
while (it.hasNext()) { while (it.hasNext()) {
sessionKey = it.next(); sessionKey = it.next();
if (sessionKey.equals(userKey)) { if (sessionKey.equals(userKey)) {
saveChatCache(chatCacheMap.get(sessionKey),null); // saveChatCache(chatCacheMap.get(sessionKey),null);
continue; continue;
} }
history = chatCacheMap.get(sessionKey).getInfoPoint(); history = chatCacheMap.get(sessionKey).getInfoPoint();
...@@ -246,6 +251,8 @@ public class ChatCacheController { ...@@ -246,6 +251,8 @@ public class ChatCacheController {
helper = new SqlHelper(); helper = new SqlHelper();
archiveInfo = helper.queryUserLastGameArchive(userKey); archiveInfo = helper.queryUserLastGameArchive(userKey);
helper.destroy();
} catch(Exception e){ } catch(Exception e){
e.printStackTrace(); e.printStackTrace();
......
...@@ -4,9 +4,10 @@ import com.alibaba.fastjson.JSON; ...@@ -4,9 +4,10 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv; import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import com.qiwu.chatbotbackend.entity.Condition; import com.qiwu.chatbotbackend.entity.Action;
import com.qiwu.chatbotbackend.entity.Solution; import com.qiwu.chatbotbackend.entity.Solution;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.task.utils.GameBotUtil;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -20,13 +21,13 @@ public class FormsPoster { ...@@ -20,13 +21,13 @@ public class FormsPoster {
LogWriter logWriter; LogWriter logWriter;
static String TALKER = "【(.*?)@.*?】"; public static String TALKER = "【(.*?)@.*?】";
@Value("${qa.url}") @Value("${qa.url}")
public String QA_URL; public String QA_URL;
public void setQaUrl(String qaUrl) { public void setQaUrl(String qaUrl) {
QA_URL = qaUrl; QA_URL = qaUrl;
} }
...@@ -46,7 +47,7 @@ public class FormsPoster { ...@@ -46,7 +47,7 @@ public class FormsPoster {
/** /**
* 提交类型为all时,会把当前信息点和历史信息点都作为post到另一个服务器 * 提交类型为all时,会把当前信息点和历史信息点都作为post到另一个服务器,还有回答
* @param curInfoPoint * @param curInfoPoint
* @param historyInfoPoint * @param historyInfoPoint
* @param ans * @param ans
...@@ -81,6 +82,7 @@ public class FormsPoster { ...@@ -81,6 +82,7 @@ public class FormsPoster {
} }
} }
pairList.add(new BasicNameValuePair("reply", ans.getAnswer()));
logWriter.record("提交表单的数据:<br>" + pairList.toString(), 2); logWriter.record("提交表单的数据:<br>" + pairList.toString(), 2);
...@@ -119,11 +121,11 @@ public class FormsPoster { ...@@ -119,11 +121,11 @@ public class FormsPoster {
* @param curInfoPoint * @param curInfoPoint
* @param historyInfoPoint * @param historyInfoPoint
* @param ans * @param ans
* @param ansCondition * @param ansAction
* @param URL * @param URL
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
public void postTerm(Map<String ,String> curInfoPoint, Map<String ,String> historyInfoPoint, Solution ans, Condition ansCondition, String URL) throws UnsupportedEncodingException { public void postTerm(Map<String ,String> curInfoPoint, Map<String ,String> historyInfoPoint, Solution ans, Action ansAction, String URL) throws UnsupportedEncodingException {
String key, keyName; String key, keyName;
Iterator<String> k_iter = null; Iterator<String> k_iter = null;
List<BasicNameValuePair> pairList = new ArrayList<BasicNameValuePair>(); List<BasicNameValuePair> pairList = new ArrayList<BasicNameValuePair>();
...@@ -131,14 +133,14 @@ public class FormsPoster { ...@@ -131,14 +133,14 @@ public class FormsPoster {
pairList.add(new BasicNameValuePair("chat_key", curInfoPoint.get("chat_key"))); pairList.add(new BasicNameValuePair("chat_key", curInfoPoint.get("chat_key")));
pairList.add(new BasicNameValuePair("action_name", curInfoPoint.get("action_name"))); pairList.add(new BasicNameValuePair("action_name", curInfoPoint.get("action_name")));
pairList.add(new BasicNameValuePair("bot_name", curInfoPoint.get("bot_name"))); pairList.add(new BasicNameValuePair("bot_name", curInfoPoint.get("bot_name")));
k_iter = ansCondition.currentPremise.keySet().iterator(); k_iter = ansAction.currentPremise.keySet().iterator();
while (k_iter.hasNext()) { while (k_iter.hasNext()) {
key = k_iter.next().split("::")[0]; key = k_iter.next().split("::")[0];
if (curInfoPoint.get(key) != null && !curInfoPoint.equals("")) if (curInfoPoint.get(key) != null && !curInfoPoint.equals(""))
pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key))); pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key)));
} }
k_iter = ansCondition.historyPremise.keySet().iterator(); k_iter = ansAction.historyPremise.keySet().iterator();
while (k_iter.hasNext()) { while (k_iter.hasNext()) {
key = k_iter.next().split("::")[0]; key = k_iter.next().split("::")[0];
if(!historyInfoPoint.get(key).equals("")) { if(!historyInfoPoint.get(key).equals("")) {
...@@ -228,16 +230,11 @@ public class FormsPoster { ...@@ -228,16 +230,11 @@ public class FormsPoster {
if (m.find()) { if (m.find()) {
npc = m.group(1); npc = m.group(1);
if ((ResponseFilter.sameLocation((String)textscore.get(0), curInfoPoint, historyInfoPoint, gameEnv, worldController, historyInfoPoint.get("site"), logWriter) == 1)) { if ((GameBotUtil.sameLocation((String)textscore.get(0), curInfoPoint, historyInfoPoint, gameEnv, worldController, historyInfoPoint.get("site"), logWriter) == 1)) {
historyInfoPoint.put("common_answer", (String)textscore.get(0)); historyInfoPoint.put("common_answer", (String)textscore.get(0));
historyInfoPoint.put("qa_score", String.valueOf(textscore.get(1))); historyInfoPoint.put("qa_score", String.valueOf(textscore.get(1)));
break; break;
} }
} else {
logWriter.record(textscore + "没找到npc名字", 1);
historyInfoPoint.put("common_answer", ResponseFilter.appendTalker((String)textscore.get(0), historyInfoPoint, gameEnv, worldController));
historyInfoPoint.put("qa_score", String.valueOf(textscore.get(1)));
break;
} }
} }
......
package com.qiwu.chatbotbackend.servlet;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.ChatCache;
import com.qiwu.chatbotbackend.processing.ChatCacheController;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Map;
@WebListener
public class ContextDestroyListener implements ServletContextListener {
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("destory context....");
/**
* 在程序中断时先把所有存在servletContext中的对话缓存数据保存下来
*/
String chatKey;
ServletContext servletContext = sce.getServletContext();
Object obj = servletContext.getAttribute("chatCache");
ChatCache cache = null;
SqlHelper helper = null;
if(obj != null){
Map<String, ChatCache> chatCacheMap = (Map<String, ChatCache>)obj;
Iterator<String> cacheIter = chatCacheMap.keySet().iterator();
try {
helper = new SqlHelper();
while (cacheIter.hasNext()) {
chatKey = cacheIter.next();
cache = chatCacheMap.get(chatKey);
//当用户id和随机对话id不同时,表示用户为登录状态,用户登录且开始游戏,则可以存档
if (cache != null && !cache.getRandKey().equals(cache.getUserKey()) && cache.isGameStart()) {
System.out.println(String.format("saving %s", chatKey));
ChatCacheController.saveChatCache(cache, helper);
}
}
cacheIter.remove();
helper.destroy();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
...@@ -2,11 +2,10 @@ package com.qiwu.chatbotbackend.servlet; ...@@ -2,11 +2,10 @@ package com.qiwu.chatbotbackend.servlet;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.JConfig; import com.qiwu.chatbotbackend.entity.ConfigTerm;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.gameDesign.*; import com.qiwu.chatbotbackend.gameDesign.*;
import com.qiwu.chatbotbackend.processing.MyFunc; import com.qiwu.chatbotbackend.processing.MyFunc;
import com.qiwu.chatbotbackend.processing.ConditionTableController;
import com.qiwu.chatbotbackend.processing.UserInfoController; import com.qiwu.chatbotbackend.processing.UserInfoController;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
...@@ -87,15 +86,13 @@ public class GameDesignServlet extends HttpServlet { ...@@ -87,15 +86,13 @@ public class GameDesignServlet extends HttpServlet {
JSONObject gameElements = helper.queryGameElementsByBotId(dataId); JSONObject gameElements = helper.queryGameElementsByBotId(dataId);
gameElements.put("auth", request.getHeader("authorization")); gameElements.put("auth", request.getHeader("authorization"));
System.out.println(gameElements.toJSONString()); //System.out.println(gameElements.toJSONString());
botId = (Integer)gameElements.get("botId"); botId = (Integer)gameElements.get("botId");
botAccount = (String) gameElements.get("botAccount"); botAccount = (String) gameElements.get("botAccount");
userName = (String)gameElements.get("userName"); userName = (String)gameElements.get("userName");
botName = (String)gameElements.get("botName"); botName = (String)gameElements.get("botName");
//假设重建用户信息 //假设重建用户信息
if (context.getAttribute(botAccount) == null) { if (context.getAttribute(botAccount) == null) {
UserInfoController.userConfigInit(botAccount, context); UserInfoController.userConfigInit(botAccount, context);
...@@ -104,8 +101,6 @@ public class GameDesignServlet extends HttpServlet { ...@@ -104,8 +101,6 @@ public class GameDesignServlet extends HttpServlet {
UserInfo userinfo = (UserInfo) context.getAttribute(botAccount); UserInfo userinfo = (UserInfo) context.getAttribute(botAccount);
//UserInfo userinfo = new UserInfo(botAccount);
//清空之前生成的配置条目 //清空之前生成的配置条目
try { try {
flag = botInit(botId, userinfo, helper); flag = botInit(botId, userinfo, helper);
...@@ -127,7 +122,7 @@ public class GameDesignServlet extends HttpServlet { ...@@ -127,7 +122,7 @@ public class GameDesignServlet extends HttpServlet {
ldt = LocalDateTime.now(); ldt = LocalDateTime.now();
now = ldt.format(dtf); now = ldt.format(dtf);
timeUsedDetect.append("\n,预处理之后:").append(now); timeUsedDetect.append("\n,预处理之后:").append(now);
String moduleList[] = {"map", "goods", "globalVariable", "npc", "plots"}; String moduleList[] = {"map", "goods", "globalVariable", "npc", "plots", "listeningActions"};
for(String moduleName: moduleList){ for(String moduleName: moduleList){
switch (moduleName) { switch (moduleName) {
...@@ -141,7 +136,7 @@ public class GameDesignServlet extends HttpServlet { ...@@ -141,7 +136,7 @@ public class GameDesignServlet extends HttpServlet {
constructor = new PlotConstructor2(helper, botId, botAccount, keywordMap, exceptRelation, POS); constructor = new PlotConstructor2(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
root = ((PlotConstructor2) constructor).getId2j().get((String) gameElements.get("start")); root = ((PlotConstructor2) constructor).getPlotIndex().get((String) gameElements.get("start"));
break; break;
case "goods": case "goods":
moduleName2 = "物品"; moduleName2 = "物品";
...@@ -158,6 +153,10 @@ public class GameDesignServlet extends HttpServlet { ...@@ -158,6 +153,10 @@ public class GameDesignServlet extends HttpServlet {
constructor = new CharacterConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS); constructor = new CharacterConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
case "listeningActions":
moduleName2 = "生成处于监听的action";
constructor = new ListeningConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo);
default: default:
continue; continue;
...@@ -170,8 +169,8 @@ public class GameDesignServlet extends HttpServlet { ...@@ -170,8 +169,8 @@ public class GameDesignServlet extends HttpServlet {
helper.batchInsertVariableByBotId(botId, constructor); helper.batchInsertVariableByBotId(botId, constructor);
List<JSONObject> jsonList = new ArrayList<JSONObject>(); List<JSONObject> jsonList = new ArrayList<JSONObject>();
for(JConfig jConfig: constructor.getjConfigList()){ for(ConfigTerm configTerm : constructor.getConfigTermList()){
json = jConfig.toJson(constructor.getConditionDescription()); json = configTerm.toJson(constructor.getConditionDescription());
constructor.parseKeyword(json, additionalKeywords, exceptRelation, botName); constructor.parseKeyword(json, additionalKeywords, exceptRelation, botName);
jsonList.add(json); jsonList.add(json);
} }
...@@ -203,7 +202,7 @@ public class GameDesignServlet extends HttpServlet { ...@@ -203,7 +202,7 @@ public class GameDesignServlet extends HttpServlet {
//System.out.println(mergedConfigText.toString()); //System.out.println(mergedConfigText.toString());
UserInfoController.buildUserInfo(br, userinfo, true); UserInfoController.buildUserInfo(br, userinfo, true);
context.setAttribute(botAccount, userinfo); context.setAttribute(botAccount, userinfo);
ConditionTableController.writeConfigText(botAccount, userinfo); UserInfoController.writeConfigText(botAccount, userinfo);
ldt = LocalDateTime.now(); ldt = LocalDateTime.now();
now = ldt.format(dtf); now = ldt.format(dtf);
timeUsedDetect.append("\n发送post请求前:").append(now); timeUsedDetect.append("\n发送post请求前:").append(now);
...@@ -276,7 +275,7 @@ public class GameDesignServlet extends HttpServlet { ...@@ -276,7 +275,7 @@ public class GameDesignServlet extends HttpServlet {
JSONObject returnMessage = null; JSONObject returnMessage = null;
JSONObject actionPostData = new JSONObject(); JSONObject actionPostData = new JSONObject();
System.out.println("root"+ root.toJSONString()); //System.out.println("root"+ root.toJSONString());
startCondition = (String)root.get("conditionName"); startCondition = (String)root.get("conditionName");
actionPostData.put("startCondition", "start_options"); actionPostData.put("startCondition", "start_options");
actionPostData.put("botName_yhm", (String)gameElements.get("botName")); actionPostData.put("botName_yhm", (String)gameElements.get("botName"));
...@@ -294,7 +293,7 @@ public class GameDesignServlet extends HttpServlet { ...@@ -294,7 +293,7 @@ public class GameDesignServlet extends HttpServlet {
actionPostData.put("POS", POS.toString() + POS2); actionPostData.put("POS", POS.toString() + POS2);
System.out.println(actionPostData.toJSONString()); //System.out.println(actionPostData.toJSONString());
userInfo.extraInfo.put("activeAction", startCondition); userInfo.extraInfo.put("activeAction", startCondition);
try { try {
...@@ -318,7 +317,7 @@ public class GameDesignServlet extends HttpServlet { ...@@ -318,7 +317,7 @@ public class GameDesignServlet extends HttpServlet {
File file = new File(path); File file = new File(path);
String line, pair[]; String line, pair[];
System.out.println(file.getAbsolutePath()); //System.out.println(file.getAbsolutePath());
if(file.exists()){ if(file.exists()){
FileReader reader = null; FileReader reader = null;
try { try {
......
package com.qiwu.chatbotbackend.servlet; package com.qiwu.chatbotbackend.servlet;
import com.qiwu.chatbotbackend.entity.Action;
import com.qiwu.chatbotbackend.entity.ChatCache; import com.qiwu.chatbotbackend.entity.ChatCache;
import com.qiwu.chatbotbackend.entity.Condition;
import com.qiwu.chatbotbackend.entity.Solution; import com.qiwu.chatbotbackend.entity.Solution;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.processing.*; import com.qiwu.chatbotbackend.processing.*;
...@@ -39,7 +39,7 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -39,7 +39,7 @@ public class GetAnswerServlet extends HttpServlet {
Map<String, String> historyInfoPoint = null; Map<String, String> historyInfoPoint = null;
Solution bestMatch = null; Solution bestMatch = null;
BasicBotUtil botUtil = null; BasicBotUtil botUtil = null;
Condition ansCondition = null; Action ansAction = null;
boolean debugFlag = false; boolean debugFlag = false;
String ansJ = "", return_str = "", state = "", chatKey = "", botType = "", userKey = "", randKey = ""; String ansJ = "", return_str = "", state = "", chatKey = "", botType = "", userKey = "", randKey = "";
String botName = receiveParamters.get("bot_name")[0]; String botName = receiveParamters.get("bot_name")[0];
...@@ -124,22 +124,21 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -124,22 +124,21 @@ public class GetAnswerServlet extends HttpServlet {
//信息点预处理 //信息点预处理
QuestionMatcher matcher = new QuestionMatcher(curInfoPoint, historyInfoPoint, logWriter, userinfo, context, chatCache.getGameEnv(), botUtil); ActionMatcher matcher = new ActionMatcher(curInfoPoint, historyInfoPoint, logWriter, userinfo, context, chatCache.getGameEnv(), botUtil);
/*得到答案更新历史信息点&生成答案,,清楚超时chatkey_key,生成更新数据库,转成json,输出*/ /*得到答案更新历史信息点&生成答案,,清楚超时chatkey_key,生成更新数据库,转成json,输出*/
//process.removeTimeoutChatkey(context); ansAction = matcher.getBestMatch(userinfo.conditionTable, context, userinfo);
//System.out.println(userinfo.conditionTable); //测试 if (state.equals("") && ansAction.priority == -1)
ansCondition = matcher.getBestMatch(userinfo.conditionTable, context, userinfo);
if (state.equals("") && ansCondition.priority == -1)
state = "我不理解,"; state = "我不理解,";
if (state.equals("")) { if (state.equals("")) {
try { try {
bestMatch = matcher.getSolution(ansCondition, context, userinfo); System.out.println("test2");
bestMatch = matcher.getSolution(ansAction, context, userinfo);
if ((ansCondition.featureMap.containsKey("activate") && ansCondition.featureMap.containsKey("post")) || ansCondition.featureMap.containsKey("activate:after")) { if ((ansAction.featureMap.containsKey("activate") && ansAction.featureMap.containsKey("post")) || ansAction.featureMap.containsKey("activate:after")) {
//如果当前condition包含激活和提交表单两个操作,那么在所有操作操作完成之后会再激活一次待激活列表,简称后激活阶段 //如果当前condition包含激活和提交表单两个操作,那么在所有操作操作完成之后会再激活一次待激活列表,简称后激活阶段
bestMatch = matcher.postActivate(ansCondition, context, userinfo); bestMatch = matcher.postActivate(ansAction, bestMatch, context, userinfo);
} }
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -149,6 +148,10 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -149,6 +148,10 @@ public class GetAnswerServlet extends HttpServlet {
} }
//针对不同游戏类型做后处理
botUtil.postprocessing(chatKey, context, bestMatch);
historyInfoPoint.put("lastReply", bestMatch.getAnswer());
if (debugFlag) { if (debugFlag) {
matcher.appendDebugInfo(bestMatch, context); matcher.appendDebugInfo(bestMatch, context);
} }
...@@ -167,8 +170,7 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -167,8 +170,7 @@ public class GetAnswerServlet extends HttpServlet {
context.setAttribute("cacheUpdateTime", System.currentTimeMillis()); context.setAttribute("cacheUpdateTime", System.currentTimeMillis());
} }
//针对不同游戏类型做后处理
botUtil.postprocessing(chatKey, context, bestMatch);
ansJ = MyFunc.toJson(bestMatch); ansJ = MyFunc.toJson(bestMatch);
} else { } else {
......
package com.qiwu.chatbotbackend.servlet; package com.qiwu.chatbotbackend.servlet;
import com.qiwu.chatbotbackend.entity.Condition; import com.qiwu.chatbotbackend.entity.Action;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.processing.MyFunc; import com.qiwu.chatbotbackend.processing.MyFunc;
import com.qiwu.chatbotbackend.processing.UserInfoController; import com.qiwu.chatbotbackend.processing.UserInfoController;
...@@ -31,9 +31,9 @@ public class UpdateServlet extends HttpServlet { ...@@ -31,9 +31,9 @@ public class UpdateServlet extends HttpServlet {
String botAccount = request.getParameter("botAccount"); String botAccount = request.getParameter("botAccount");
UserInfo userinfo = new UserInfo(botAccount); UserInfo userinfo = new UserInfo(botAccount);
userinfo.conditionTable = new HashMap<String, List<Condition>>(); userinfo.conditionTable = new HashMap<String, List<Action>>();
List<Condition> conditionList = null; List<Action> actionList = null;
HashSet<String> keyWordSet = null; HashSet<String> keyWordSet = null;
BufferedReader br = new BufferedReader(new StringReader(request.getParameter("config_string"))); BufferedReader br = new BufferedReader(new StringReader(request.getParameter("config_string")));
...@@ -56,16 +56,16 @@ public class UpdateServlet extends HttpServlet { ...@@ -56,16 +56,16 @@ public class UpdateServlet extends HttpServlet {
} }
//line = MyFunc.convert2Utf8(line.trim()); //line = MyFunc.convert2Utf8(line.trim());
userinfo.configStr += line + "\n"; userinfo.configStr += line + "\n";
Condition condition = new Condition(); Action action = new Action();
try { try {
condition = UserInfoController.buildCondition(condition, line); action = UserInfoController.buildCondition(action, line);
conditionList = userinfo.conditionTable.get(condition.indexName); actionList = userinfo.conditionTable.get(action.indexName);
if (conditionList == null) if (actionList == null)
conditionList = new ArrayList<Condition>(); actionList = new ArrayList<Action>();
conditionList.add(condition); actionList.add(action);
userinfo.conditionTable.put(condition.indexName, conditionList); userinfo.conditionTable.put(action.indexName, actionList);
/* /*
for(String name:condition.indexName){ for(String name:action.indexName){
userinfo.conditionTable.put() userinfo.conditionTable.put()
} }
*/ */
......
package com.qiwu.chatbotbackend.servlet; package com.qiwu.chatbotbackend.servlet;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.processing.ConditionTableController;
import com.qiwu.chatbotbackend.processing.UserInfoController; import com.qiwu.chatbotbackend.processing.UserInfoController;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
...@@ -10,7 +9,10 @@ import javax.servlet.annotation.WebServlet; ...@@ -10,7 +9,10 @@ import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
@WebServlet(name = "UpdateSingleConfigServlet", urlPatterns = {"/update2"}) @WebServlet(name = "UpdateSingleConfigServlet", urlPatterns = {"/update2"})
public class UpdateSingleConfigServlet extends HttpServlet { public class UpdateSingleConfigServlet extends HttpServlet {
...@@ -26,26 +28,26 @@ public class UpdateSingleConfigServlet extends HttpServlet { ...@@ -26,26 +28,26 @@ public class UpdateSingleConfigServlet extends HttpServlet {
if (context.getAttribute(userName) != null) { if (context.getAttribute(userName) != null) {
switch (processType) { switch (processType) {
case "insert_config": case "insert_config":
ConditionTableController.insertConfig(userName, configId, data, context); UserInfoController.insertConfig(userName, configId, data, context);
break; break;
case "update_config": case "update_config":
ConditionTableController.deleteConfig(userName, configId, data, context); UserInfoController.deleteConfig(userName, configId, data, context);
ConditionTableController.insertConfig(userName, configId, data, context); UserInfoController.insertConfig(userName, configId, data, context);
break; break;
case "delete_config": case "delete_config":
ConditionTableController.deleteConfig(userName, configId, data, context); UserInfoController.deleteConfig(userName, configId, data, context);
break; break;
case "insert_variable": case "insert_variable":
ConditionTableController.updateVariable(userName, configId, data, context); UserInfoController.updateVariable(userName, configId, data, context);
break; break;
case "delete_variable": case "delete_variable":
ConditionTableController.deleteVariable(userName, configId, data, context); UserInfoController.deleteVariable(userName, configId, data, context);
break; break;
case "update_variable": case "update_variable":
ConditionTableController.updateVariable(userName, configId, data, context); UserInfoController.updateVariable(userName, configId, data, context);
break; break;
case "extra_info": case "extra_info":
ConditionTableController.updateExtraInfo(userName, data, context); UserInfoController.updateExtraInfo(userName, data, context);
break; break;
case "batch_update": case "batch_update":
...@@ -82,7 +84,7 @@ public class UpdateSingleConfigServlet extends HttpServlet { ...@@ -82,7 +84,7 @@ public class UpdateSingleConfigServlet extends HttpServlet {
String returnMessage = ""; String returnMessage = "";
UserInfo userinfo = (UserInfo) context.getAttribute(userName); UserInfo userinfo = (UserInfo) context.getAttribute(userName);
returnMessage = ConditionTableController.writeConfigText(userName, userinfo); returnMessage = UserInfoController.writeConfigText(userName, userinfo);
return returnMessage; return returnMessage;
} }
......
package com.qiwu.chatbotbackend.task.utils; package com.qiwu.chatbotbackend.task.utils;
import com.qiwu.chatbotbackend.entity.Condition; import com.qiwu.chatbotbackend.entity.Action;
import com.qiwu.chatbotbackend.entity.Solution; import com.qiwu.chatbotbackend.entity.Solution;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.processing.LogWriter; import com.qiwu.chatbotbackend.processing.LogWriter;
...@@ -126,6 +126,7 @@ public class BasicBotUtil { ...@@ -126,6 +126,7 @@ public class BasicBotUtil {
} }
public boolean postprocessing(String chatKey, ServletContext context, Solution bestMatch){ public boolean postprocessing(String chatKey, ServletContext context, Solution bestMatch){
return true; return true;
} }
...@@ -173,7 +174,7 @@ public class BasicBotUtil { ...@@ -173,7 +174,7 @@ public class BasicBotUtil {
/** /**
* 额外的更新操作 * 额外的更新操作
*/ */
public void extraOperation(Condition ansCondition, Solution solution) throws IOException { public void extraOperation(Action ansAction, Solution solution) throws IOException {
} }
......
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