Commit 04bd4be9 by 赵国君

殷勤穿过来的表单,你我替换

parent 3e9933cf
...@@ -846,19 +846,19 @@ public class ActionUtils { ...@@ -846,19 +846,19 @@ public class ActionUtils {
conditionExtraKeywords.putIfAbsent(DEFAULT_CONDITION + "_head", new HashSet<String>()); conditionExtraKeywords.putIfAbsent(DEFAULT_CONDITION + "_head", new HashSet<String>());
conditionExtraKeywords.putIfAbsent(DEFAULT_CONDITION + "_tail", new HashSet<String>()); conditionExtraKeywords.putIfAbsent(DEFAULT_CONDITION + "_tail", new HashSet<String>());
String condTemple = patternConditionJson.toJSONString(); String condTemple = patternConditionJson.toJSONString();
for(int i = 0;i < 100;i++){ int i = 0;
boolean beEnd = false;
while(true) {
//给condition的名字添加后缀,因为游戏中可能用到condition的复制,但值域和名字不一样 //给condition的名字添加后缀,因为游戏中可能用到condition的复制,但值域和名字不一样
if(i == 0) if(i == 0)
postfix = ""; postfix = "";
else else
postfix = "_" + String.valueOf(i); postfix = "_" + String.valueOf(i);
activeFlag = "0";
conditionJson = (JSONObject) JSON.parse(condTemple); conditionJson = (JSONObject) JSON.parse(condTemple);
// conditionJson = (JSONObject) patternConditionJson.clone(); String originName = conditionJson.getString("conditionName");
conditionName = conditionJson.getString("conditionName") + postfix; conditionName = originName + postfix;
conditionName2 = conditionName + "_indep"; conditionName2 = conditionName + "_indep";
if(conditionExtraKeywords.containsKey(conditionName + "_tail")) { if(conditionExtraKeywords.containsKey(conditionName + "_tail")) {
...@@ -868,13 +868,20 @@ public class ActionUtils { ...@@ -868,13 +868,20 @@ public class ActionUtils {
conditionJson.put("conditionName", conditionName2); conditionJson.put("conditionName", conditionName2);
conditionAppendKeyword2(conditionName2, conditionJson, conditionExtraKeywords, macroAppendMap); conditionAppendKeyword2(conditionName2, conditionJson, conditionExtraKeywords, macroAppendMap);
conditionName = conditionName2; conditionName = conditionName2;
} else { } else if(i>1 && !conditionExtraKeywords.containsKey(originName + "_tail")) {
conditionName = originName;
beEnd = true;
} else if(i == 0) {
++i;
continue; continue;
} else {
break;
} }
if(conditionJson.getBoolean("active") && !conditionName.equals(startCondition)) if(conditionJson.getBoolean("active") && !conditionName.equals(startCondition))
conditionJson.put("active", false); conditionJson.put("active", false);
activeFlag = "0";
actionText = generateSingleActionText(conditionName, conditionJson); actionText = generateSingleActionText(conditionName, conditionJson);
if(startCondition.equals(conditionName)) { if(startCondition.equals(conditionName)) {
conditionJson.put("active", true); conditionJson.put("active", true);
...@@ -894,6 +901,9 @@ public class ActionUtils { ...@@ -894,6 +901,9 @@ public class ActionUtils {
add(finalRelationName); add(finalRelationName);
} }
}); });
++i;
if(beEnd == true)
break;
} }
} }
parameters.put("conditionData", conditionData); parameters.put("conditionData", conditionData);
......
...@@ -20,6 +20,8 @@ import java.io.OutputStream; ...@@ -20,6 +20,8 @@ import java.io.OutputStream;
import java.text.ParseException; import java.text.ParseException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import static com.qiwu.chatbotbackend.Config.Config.*; import static com.qiwu.chatbotbackend.Config.Config.*;
import static com.qiwu.chatbotbackend.processing.ChatCacheController.COMBINE_PUNC2; import static com.qiwu.chatbotbackend.processing.ChatCacheController.COMBINE_PUNC2;
...@@ -30,28 +32,37 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -30,28 +32,37 @@ public class GetAnswerServlet extends HttpServlet {
/** /**
* GetAnswerServlet就是处理post请求并返回答案的入口 * GetAnswerServlet就是处理post请求并返回答案的入口
*/ */
//String LOG_PATH = "/home/hxw/source/logs/";
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8");
Map<String, String[]> receiveParamters = new HashMap<>(request.getParameterMap()); Map<String, String[]> requestParamters = new HashMap<>(request.getParameterMap());
Map<String, String> receiveParamters = new HashMap<>();
Set<Entry<String, String[]>> entrySet = requestParamters.entrySet();
String tmpStr;
for(Map.Entry<String, String[]> entry : entrySet) {
if(entry.getValue().length > 0) {
tmpStr = entry.getValue()[0];
if(tmpStr == null || tmpStr.equals(""))
continue;
tmpStr = tmpStr.replace("qiwu", "我");
//tmpStr = tmpStr.replace("qiwu", "你");
receiveParamters.put(entry.getKey(), tmpStr);
}
}
String botName = receiveParamters.get("bot_name");
Map<String ,String> curInfoPoint = new HashMap<String, String>(); Map<String ,String> curInfoPoint = new HashMap<String, String>();
Solution bestMatch = null; Solution bestMatch = null;
BasicBotUtil botUtil = null; BasicBotUtil botUtil = null;
Action ansAction = 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];
OutputStream out = response.getOutputStream(); OutputStream out = response.getOutputStream();
ServletContext context = this.getServletContext(); ServletContext context = this.getServletContext();
//如果有client_id,会用@分隔 //如果有client_id,会用@分隔
chatKey = receiveParamters.get("chat_key")[0]; chatKey = receiveParamters.get("chat_key");
String chatKeys[] = receiveParamters.get("chat_key")[0].split(COMBINE_PUNC2); String chatKeys[] = receiveParamters.get("chat_key").split(COMBINE_PUNC2);
if(chatKeys.length == 1){ if(chatKeys.length == 1){
userKey = chatKeys[0]; userKey = chatKeys[0];
randKey = chatKeys[0]; randKey = chatKeys[0];
...@@ -60,23 +71,19 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -60,23 +71,19 @@ public class GetAnswerServlet extends HttpServlet {
randKey = chatKeys[1]; randKey = chatKeys[1];
} }
receiveParamters.put("userKey", new String[]{userKey}); receiveParamters.put("userKey", userKey);
receiveParamters.put("randKey", new String[]{randKey}); receiveParamters.put("randKey", randKey);
try { try {
LogWriter logWriter = new LogWriter(LOG_PATH, chatKey); LogWriter logWriter = new LogWriter(LOG_PATH, chatKey);
UserInfo userinfo = null; UserInfo userinfo = null;
UserInfoController uiController = new UserInfoController(); UserInfoController uiController = new UserInfoController();
logWriter.record("query bot config", 0); logWriter.record("query bot config", 0);
userinfo = uiController.userInfoQuery(request.getParameter("bot_name"), context); userinfo = uiController.userInfoQuery(request.getParameter("bot_name"), context);
if (userinfo != null) { if (userinfo != null) {
//获得用户历史信息 //获得用户历史信息
ChatCache chatCache = null; ChatCache chatCache = null;
...@@ -96,16 +103,12 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -96,16 +103,12 @@ public class GetAnswerServlet extends HttpServlet {
if (chatCache == null) { if (chatCache == null) {
throw (new Exception("chatCache初始化失败")); throw (new Exception("chatCache初始化失败"));
} }
/** /**
* 如果读档成功,则返回存档前的状态(包括最后一个condition和最后的回答) * 如果读档成功,则返回存档前的状态(包括最后一个condition和最后的回答)
* 如果读档失败,则开始新的游戏,读档失败的判断标准是除了初始化数据外没有其他任何数据 * 如果读档失败,则开始新的游戏,读档失败的判断标准是除了初始化数据外没有其他任何数据
*/ */
//historyInfoPoint = chatCache.getInfoPoint();
switch (botType) { switch (botType) {
case "game": case "game":
WorldController worldController = new WorldController(logWriter, userinfo); WorldController worldController = new WorldController(logWriter, userinfo);
......
...@@ -35,7 +35,7 @@ public class BasicBotUtil { ...@@ -35,7 +35,7 @@ public class BasicBotUtil {
this.chatCache = chatCache; this.chatCache = chatCache;
} }
public boolean preprocessing(Map<String, String[]> receiveParameters, ServletContext context) throws IOException { public boolean preprocessing(Map<String, String> receiveParameters, ServletContext context) throws IOException {
return infoPointPreprocessing(receiveParameters, context, true); return infoPointPreprocessing(receiveParameters, context, true);
...@@ -51,7 +51,7 @@ public class BasicBotUtil { ...@@ -51,7 +51,7 @@ public class BasicBotUtil {
* @return * @return
* @throws IOException * @throws IOException
*/ */
public boolean infoPointPreprocessing(Map<String, String[]> receiveParameters, ServletContext context, Boolean setUnknown) throws IOException { public boolean infoPointPreprocessing(Map<String, String> receiveParameters, ServletContext context, Boolean setUnknown) throws IOException {
String return_str = "", k, botType = ""; String return_str = "", k, botType = "";
String receiveParameterStr = ""; String receiveParameterStr = "";
...@@ -75,18 +75,15 @@ public class BasicBotUtil { ...@@ -75,18 +75,15 @@ public class BasicBotUtil {
receiveParameterStr+= "-----------------------------------------识别数据列表-------------------------------------------<br>"; receiveParameterStr+= "-----------------------------------------识别数据列表-------------------------------------------<br>";
while (iit.hasNext()) { while (iit.hasNext()) {
k = iit.next(); k = iit.next();
//
receiveParameterStr += k + ": "; receiveParameterStr += k + ": ";
curInfoPoint.put(k, receiveParameters.get(k)[0]); curInfoPoint.put(k, receiveParameters.get(k));
if (k.equals("debug_mode") || k.equals("debug_rule")) if (k.equals("debug_mode") || k.equals("debug_rule"))
debugFlag = true; debugFlag = true;
String values[] = receiveParameters.get(k); String values = receiveParameters.get(k);
receiveParameterStr += values + " " + "<br>";
receiveParameterStr += values[0] + " " + "<br>"; if (values.equals(":")) {
if (values[0].equals(":")) {
curInfoPoint.put(k, ""); curInfoPoint.put(k, "");
} }
} }
......
...@@ -44,7 +44,7 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -44,7 +44,7 @@ public class GameBotUtil extends BasicBotUtil{
* @throws IOException * @throws IOException
*/ */
@Override @Override
public boolean preprocessing(Map<String, String[]> receiveParameters, ServletContext context) throws IOException { public boolean preprocessing(Map<String, String> receiveParameters, ServletContext context) throws IOException {
Boolean debugFlag = super.infoPointPreprocessing(receiveParameters, context, false); Boolean debugFlag = super.infoPointPreprocessing(receiveParameters, context, false);
//将要去的地点的别名替换为真名 //将要去的地点的别名替换为真名
......
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