Commit f4ead641 by 赵国君

日志修改

parent 115271fa
...@@ -88,7 +88,9 @@ public class ActionMatcher { ...@@ -88,7 +88,9 @@ public class ActionMatcher {
if (action.getStatus().equals("waiting")){ if (action.getStatus().equals("waiting")){
logWriter.record("-----------------------------------检索到配置条目", 0); logWriter.record("-----------------------------------检索到配置条目", 0);
logWriter.record(userinfo.id2config.get(action.getId()), 1); //logWriter.record(userinfo.id2config.get(action.getId()), 1);
Action action2 = userinfo.id2condition.get(action.getId());
logWriter.record(action2.getConfigName() + " - " + action2.getId(), 1);
//是否有激活操作,如果有激活操作且没有提交表单则判断是否满足条件,如果有激活有提交表单,则放在整个操作完成(getSolution)之后再激活 //是否有激活操作,如果有激活操作且没有提交表单则判断是否满足条件,如果有激活有提交表单,则放在整个操作完成(getSolution)之后再激活
if (action.getFeatureMap().get("activate") != null && !action.getFeatureMap().containsKey("post")) { if (action.getFeatureMap().get("activate") != null && !action.getFeatureMap().containsKey("post")) {
...@@ -163,8 +165,9 @@ public class ActionMatcher { ...@@ -163,8 +165,9 @@ public class ActionMatcher {
logWriter.record("-----------------------------------检索到配置条目", 0); logWriter.record("-----------------------------------检索到配置条目", 0);
logWriter.record(userinfo.id2config.get(action.getId()), 1); //logWriter.record(userinfo.id2config.get(action.getId()), 1);
Action action2 = userinfo.id2condition.get(action.getId());
logWriter.record(action2.getConfigName() + " - " + action2.getId(), 1);
if(higherPriority(action, bestMatch)) if(higherPriority(action, bestMatch))
replaceFlag = true; replaceFlag = true;
...@@ -678,7 +681,21 @@ public class ActionMatcher { ...@@ -678,7 +681,21 @@ public class ActionMatcher {
historyInfoPoint.put("currentAction", next); historyInfoPoint.put("currentAction", next);
historyInfoPoint.put("activeList", historyInfoPoint.get("activeList") + "|" + next); historyInfoPoint.put("activeList", historyInfoPoint.get("activeList") + "|" + next);
logWriter.record("处理完成后的信息点:<br>" + historyInfoPoint.toString(), 1); // logWriter.record("处理完成后的信息点:<br>" + historyInfoPoint.toString(), 1);
StringBuilder sb = new StringBuilder("处理完成后的信息点:<br>");
for(Map.Entry<String, String> entry : historyInfoPoint.entrySet()) {
if(entry.getValue()==null || entry.getValue().equals(""))
continue;
switch (entry.getKey()) {
case "unknownText":
case "unknownTextList":
case "finalUnknownText":
break;
default:
sb.append(entry.getKey() + ":" + entry.getValue() + ", ");
}
}
logWriter.record(sb.toString(), 1);
HashSet<String> skipSet = new HashSet<String>() { HashSet<String> skipSet = new HashSet<String>() {
{ {
......
package com.qiwu.chatbotbackend.task.utils; package com.qiwu.chatbotbackend.task.utils;
import com.qiwu.chatbotbackend.entity.Action; import com.qiwu.chatbotbackend.entity.Action;
import com.qiwu.chatbotbackend.entity.ChatCache; import com.qiwu.chatbotbackend.entity.ChatCache;
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;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class BasicBotUtil { public class BasicBotUtil {
Map<String, String> curInfoPoint = null; Map<String, String> curInfoPoint = null;
UserInfo userinfo = null; UserInfo userinfo = null;
LogWriter logWriter = null; LogWriter logWriter = null;
ChatCache chatCache = null; ChatCache chatCache = null;
public String botType = "basic"; public String botType = "basic";
public ChatCache getChatCache() { public ChatCache getChatCache() {
return chatCache; return chatCache;
} }
public BasicBotUtil(){}; public BasicBotUtil(){};
public BasicBotUtil(Map<String, String> curInfoPoint, ChatCache chatCache, UserInfo userinfo, LogWriter logWriter){ public BasicBotUtil(Map<String, String> curInfoPoint, ChatCache chatCache, UserInfo userinfo, LogWriter logWriter){
this.curInfoPoint = curInfoPoint; this.curInfoPoint = curInfoPoint;
this.userinfo = userinfo; this.userinfo = userinfo;
this.logWriter = logWriter; this.logWriter = logWriter;
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);
} }
//在接收到请求后对数据做处理,转化为系统可以处理的数据 //在接收到请求后对数据做处理,转化为系统可以处理的数据
/** /**
* *
* @param receiveParameters * @param receiveParameters
* @param context * @param context
* @param setUnknown 如果什么都没识别到就将上一个激活的condition设为unknown * @param setUnknown 如果什么都没识别到就将上一个激活的condition设为unknown
* @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 = "";
boolean debugFlag = false; boolean debugFlag = false;
HashSet<String> skipSet = new HashSet<String>() { HashSet<String> skipSet = new HashSet<String>() {
{ {
add("chat_key"); add("chat_key");
add("randKey"); add("randKey");
add("userKey"); add("userKey");
add("action_name"); add("action_name");
add("bot_name"); add("bot_name");
add("emptySet"); add("emptySet");
add("query_text"); add("query_text");
} }
}; };
//输出所有actionName的值 //输出所有actionName的值
Iterator<String> iit = receiveParameters.keySet().iterator(); Iterator<String> iit = receiveParameters.keySet().iterator();
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)[0]);
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[0] + " " + "<br>"; receiveParameterStr += values[0] + " " + "<br>";
if (values[0].equals(":")) { if (values[0].equals(":")) {
curInfoPoint.put(k, ""); curInfoPoint.put(k, "");
} }
} }
logWriter.record(receiveParameterStr, 0); logWriter.record(receiveParameterStr, 0);
System.out.println(receiveParameterStr.toString()); System.out.println(receiveParameterStr.toString());
//如果引擎什么信息都没识别到,那就将上一轮的nextStep(也就是当前轮的actionName)设为unknown //如果引擎什么信息都没识别到,那就将上一轮的nextStep(也就是当前轮的actionName)设为unknown
iit = curInfoPoint.keySet().iterator(); iit = curInfoPoint.keySet().iterator();
boolean unknown_flag = setUnknown; boolean unknown_flag = setUnknown;
while (iit.hasNext()) { while (iit.hasNext()) {
k = iit.next(); k = iit.next();
String values = curInfoPoint.get(k); String values = curInfoPoint.get(k);
if (skipSet.contains(k)) if (skipSet.contains(k))
continue; continue;
if (!values.equals("")) { if (!values.equals("")) {
unknown_flag = false; unknown_flag = false;
break; break;
} }
} }
String currentAction = ""; String currentAction = "";
if (chatCache.getInfoPoint().containsKey("currentAction")) if (chatCache.getInfoPoint().containsKey("currentAction"))
currentAction = chatCache.getInfoPoint().get("currentAction"); currentAction = chatCache.getInfoPoint().get("currentAction");
else if (userinfo.extraInfo.containsKey("activeAction")) { else if (userinfo.extraInfo.containsKey("activeAction")) {
currentAction = userinfo.extraInfo.get("activeAction"); currentAction = userinfo.extraInfo.get("activeAction");
chatCache.getInfoPoint().put("currentAction", currentAction); chatCache.getInfoPoint().put("currentAction", currentAction);
} else } else
currentAction = " "; currentAction = " ";
curInfoPoint.put("emptySet", " "); curInfoPoint.put("emptySet", " ");
if (chatCache.getInfoPoint().get("activeList") == null) { if (chatCache.getInfoPoint().get("activeList") == null) {
chatCache.getInfoPoint().put("activeList", currentAction); chatCache.getInfoPoint().put("activeList", currentAction);
} }
if (unknown_flag && !currentAction.equals("")) { if (unknown_flag && !currentAction.equals("")) {
String i = "unknown"; String i = "unknown";
curInfoPoint.put(currentAction, i); curInfoPoint.put(currentAction, i);
} }
logWriter.record("historyInfoPoint:" + chatCache.getInfoPoint().toString(), 1); // logWriter.record("historyInfoPoint:" + chatCache.getInfoPoint().toString(), 1);
Map<String, String> _info = chatCache.getInfoPoint();
StringBuilder sb = new StringBuilder("historyInfoPoint:");
for(Map.Entry<String, String> entry : _info.entrySet()) {
return debugFlag; if(entry.getValue()==null || entry.getValue().equals(""))
} continue;
switch (entry.getKey()) {
public boolean postprocessing(String chatKey, ServletContext context, Solution bestMatch){ case "unknownText":
if(chatCache.getInfoPoint().get("error_message") != null && chatCache.getInfoPoint().get("error_message") != ""){ case "unknownTextList":
bestMatch.setAnswer(bestMatch.getAnswer() + chatCache.getInfoPoint().get("error_message")); case "finalUnknownText":
} break;
default:
sb.append(entry.getKey() + ":" + entry.getValue() + ", ");
return true; }
} }
logWriter.record(sb.toString(), 1);
/**
* 从当前信息点或者已知信息点中提取关键词 return debugFlag;
* @param infoPoint }
* @param infoPoint2
* @param chooseLater public boolean postprocessing(String chatKey, ServletContext context, Solution bestMatch){
* @param actionName if(chatCache.getInfoPoint().get("error_message") != null && chatCache.getInfoPoint().get("error_message") != ""){
* @return bestMatch.setAnswer(bestMatch.getAnswer() + chatCache.getInfoPoint().get("error_message"));
*/ }
public String getKeyword(Map<String, String> infoPoint, Map<String, String> infoPoint2, Boolean chooseLater, String actionName){
String keyword = "";
String nameSeries[] = actionName.split("_"); return true;
}
/**
* 如果chooseLater为真,则先提取infoPint2中的关键字,如果infoPoint2中不存在,再提取infoPoint中的关键字
*/ /**
if(chooseLater){ * 从当前信息点或者已知信息点中提取关键词
keyword = infoPoint2.get(actionName); * @param infoPoint
if(keyword != null && !keyword.equals("")) * @param infoPoint2
return keyword; * @param chooseLater
} * @param actionName
keyword = infoPoint.get(actionName); * @return
*/
public String getKeyword(Map<String, String> infoPoint, Map<String, String> infoPoint2, Boolean chooseLater, String actionName){
return keyword; String keyword = "";
}; String nameSeries[] = actionName.split("_");
/** /**
* 更新历史信息点中的某一个键值对 * 如果chooseLater为真,则先提取infoPint2中的关键字,如果infoPoint2中不存在,再提取infoPoint中的关键字
* @param variableName */
* @param updateValue if(chooseLater){
*/ keyword = infoPoint2.get(actionName);
public void putKeyword(String variableName, String updateValue){ if(keyword != null && !keyword.equals(""))
chatCache.getInfoPoint().put(variableName, updateValue); return keyword;
} }
keyword = infoPoint.get(actionName);
public String knowledgeProcess(String variableName, String updateValue){
return updateValue;
return keyword;
} };
/** /**
* 额外的更新操作 * 更新历史信息点中的某一个键值对
*/ * @param variableName
public void extraOperation(Action ansAction, Solution solution) throws IOException { * @param updateValue
*/
} public void putKeyword(String variableName, String updateValue){
chatCache.getInfoPoint().put(variableName, updateValue);
//将文本中存在的变量槽位{npc_xxx}替换成变量值 }
public String varSlotReplace(String text){
public String knowledgeProcess(String variableName, String updateValue){
String VARIABLE_REPLACE_PATTERN = "(\\{.*?\\-[12]\\})"; return updateValue;
Pattern replacePattern = Pattern.compile(VARIABLE_REPLACE_PATTERN);
}
//用正则表达式将回答中的变量模板{conditionName-2}替换成后台存储的变量值
String keyword, variable,reply = text; /**
Matcher m = replacePattern.matcher(reply); * 额外的更新操作
while (m.find()) { */
variable = m.group(1).substring(1, m.group(1).length() - 3); public void extraOperation(Action ansAction, Solution solution) throws IOException {
if (m.group(1).endsWith("-1}")) {
if (curInfoPoint.get(variable) != null && !curInfoPoint.get(variable).equals("")) { }
keyword = curInfoPoint.get(variable);
//将文本中存在的变量槽位{npc_xxx}替换成变量值
public String varSlotReplace(String text){
if(keyword.contains(":"))
keyword = keyword.split(":")[1]; String VARIABLE_REPLACE_PATTERN = "(\\{.*?\\-[12]\\})";
Pattern replacePattern = Pattern.compile(VARIABLE_REPLACE_PATTERN);
reply = reply.replace("{" + variable + "-1}", keyword);
} //用正则表达式将回答中的变量模板{conditionName-2}替换成后台存储的变量值
} else if (m.group(1).endsWith("-2}")) { String keyword, variable,reply = text;
if (chatCache.getInfoPoint().get(variable) != null) Matcher m = replacePattern.matcher(reply);
if(chatCache.getInfoPoint().get(variable).equals("do_reset")){ while (m.find()) {
reply = reply.replace("{" + variable + "-2}", ""); variable = m.group(1).substring(1, m.group(1).length() - 3);
}else if (m.group(1).endsWith("-1}")) {
reply = reply.replace("{" + variable + "-2}", chatCache.getInfoPoint().get(variable)); if (curInfoPoint.get(variable) != null && !curInfoPoint.get(variable).equals("")) {
} keyword = curInfoPoint.get(variable);
}
return reply; if(keyword.contains(":"))
} keyword = keyword.split(":")[1];
}
reply = reply.replace("{" + variable + "-1}", keyword);
}
} else if (m.group(1).endsWith("-2}")) {
if (chatCache.getInfoPoint().get(variable) != null)
if(chatCache.getInfoPoint().get(variable).equals("do_reset")){
reply = reply.replace("{" + variable + "-2}", "");
}else
reply = reply.replace("{" + variable + "-2}", chatCache.getInfoPoint().get(variable));
}
}
return reply;
}
}
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