Commit 04bd4be9 by 赵国君

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

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