package com.qiwu.chatbotbackend.task.utils; import com.qiwu.chatbotbackend.entity.Solution; import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.processing.LogWriter; import javax.servlet.ServletContext; import java.io.IOException; import java.util.HashSet; import java.util.Iterator; import java.util.Map; public class BasicBotUtil { Map curInfoPoint = null; Map historyInfoPoint = null; UserInfo userinfo = null; LogWriter logWriter = null; public BasicBotUtil(){}; public BasicBotUtil(Map curInfoPoint, Map historyInfoPoint, UserInfo userinfo, LogWriter logWriter){ this.curInfoPoint = curInfoPoint; this.historyInfoPoint = historyInfoPoint; this.userinfo = userinfo; this.logWriter = logWriter; } public boolean preprocessing(Map receiveParameters, ServletContext context) throws IOException { return infoPointPreprocessing(receiveParameters, context); } public boolean infoPointPreprocessing(Map receiveParameters, ServletContext context) throws IOException { String return_str = "", k, botType = ""; String receiveParameterStr = ""; boolean debugFlag = false; HashSet skipSet = new HashSet() { { add("chat_key"); add("action_name"); add("bot_name"); add("emptySet"); add("query_text"); } }; //输出所有actionName的值 Iterator iit = receiveParameters.keySet().iterator(); receiveParameterStr+= "-----------------------------------------识别数据列表-------------------------------------------
"; while (iit.hasNext()) { k = iit.next(); // receiveParameterStr += k + ": "; curInfoPoint.put(k, receiveParameters.get(k)[0]); if (k.equals("debug_mode") || k.equals("debug_rule")) debugFlag = true; String values[] = receiveParameters.get(k); // for (String v : values) { // receiveParameterStr += v + " "; // } receiveParameterStr += values[0] + " " + "
"; if (values[0].equals(":")) { curInfoPoint.put(k, ""); } } logWriter.record(receiveParameterStr, 0); System.out.println(receiveParameterStr.toString()); //如果引擎什么信息都没识别到,那就将上一轮的nextStep(也就是当前轮的actionName)设为unknown iit = curInfoPoint.keySet().iterator(); boolean unknown_flag = true; while (iit.hasNext()) { k = iit.next(); String values = curInfoPoint.get(k); if (skipSet.contains(k)) continue; if (!values.equals("")) { unknown_flag = false; break; } } String currentAction = ""; if (historyInfoPoint.containsKey("currentAction")) currentAction = historyInfoPoint.get("currentAction"); else if (userinfo.extraInfo.containsKey("activeAction")) { currentAction = userinfo.extraInfo.get("activeAction"); historyInfoPoint.put("currentAction", currentAction); } else currentAction = " "; curInfoPoint.put("emptySet", " "); if (historyInfoPoint.get("activeList") == null) { historyInfoPoint.put("activeList", currentAction); } if (unknown_flag && !currentAction.equals("")) { String i = "unknown"; curInfoPoint.put(currentAction, i); } logWriter.record("historyInfoPoint:" + historyInfoPoint.toString(), 1); return debugFlag; } public boolean postprocessing(String chatKey, ServletContext context, Solution bestMatch){ return true; } public String getKeyword(Map infoPoint, Map infoPoint2, Boolean chooseLater, String actionName){ String keyword = ""; String nameSeries[] = actionName.split("_"); /** * 如果chooseLater为真,则先提取infoPint2中的关键字,如果infoPoint2中不存在,再提取infoPoint中的关键字 */ if(chooseLater){ keyword = infoPoint2.get(actionName); if(keyword != null && !keyword.equals("")) return keyword; } keyword = infoPoint.get(actionName); return keyword; }; public void putKeyword(String variableName, String updateValue){ historyInfoPoint.put(variableName, updateValue); } public String knowledgeProcess(String variableName, String updateValue){ return updateValue; } }