Commit f4ead641 by 赵国君

日志修改

parent 115271fa
......@@ -88,7 +88,9 @@ public class ActionMatcher {
if (action.getStatus().equals("waiting")){
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)之后再激活
if (action.getFeatureMap().get("activate") != null && !action.getFeatureMap().containsKey("post")) {
......@@ -163,8 +165,9 @@ public class ActionMatcher {
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))
replaceFlag = true;
......@@ -678,7 +681,21 @@ public class ActionMatcher {
historyInfoPoint.put("currentAction", 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>() {
{
......
package com.qiwu.chatbotbackend.task.utils;
import com.qiwu.chatbotbackend.entity.Action;
import com.qiwu.chatbotbackend.entity.ChatCache;
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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class BasicBotUtil {
Map<String, String> curInfoPoint = null;
UserInfo userinfo = null;
LogWriter logWriter = null;
ChatCache chatCache = null;
public String botType = "basic";
public ChatCache getChatCache() {
return chatCache;
}
public BasicBotUtil(){};
public BasicBotUtil(Map<String, String> curInfoPoint, ChatCache chatCache, UserInfo userinfo, LogWriter logWriter){
this.curInfoPoint = curInfoPoint;
this.userinfo = userinfo;
this.logWriter = logWriter;
this.chatCache = chatCache;
}
public boolean preprocessing(Map<String, String[]> receiveParameters, ServletContext context) throws IOException {
return infoPointPreprocessing(receiveParameters, context, true);
}
//在接收到请求后对数据做处理,转化为系统可以处理的数据
/**
*
* @param receiveParameters
* @param context
* @param setUnknown 如果什么都没识别到就将上一个激活的condition设为unknown
* @return
* @throws IOException
*/
public boolean infoPointPreprocessing(Map<String, String[]> receiveParameters, ServletContext context, Boolean setUnknown) throws IOException {
String return_str = "", k, botType = "";
String receiveParameterStr = "";
boolean debugFlag = false;
HashSet<String> skipSet = new HashSet<String>() {
{
add("chat_key");
add("randKey");
add("userKey");
add("action_name");
add("bot_name");
add("emptySet");
add("query_text");
}
};
//输出所有actionName的值
Iterator<String> iit = receiveParameters.keySet().iterator();
receiveParameterStr+= "-----------------------------------------识别数据列表-------------------------------------------<br>";
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);
receiveParameterStr += values[0] + " " + "<br>";
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 = setUnknown;
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 (chatCache.getInfoPoint().containsKey("currentAction"))
currentAction = chatCache.getInfoPoint().get("currentAction");
else if (userinfo.extraInfo.containsKey("activeAction")) {
currentAction = userinfo.extraInfo.get("activeAction");
chatCache.getInfoPoint().put("currentAction", currentAction);
} else
currentAction = " ";
curInfoPoint.put("emptySet", " ");
if (chatCache.getInfoPoint().get("activeList") == null) {
chatCache.getInfoPoint().put("activeList", currentAction);
}
if (unknown_flag && !currentAction.equals("")) {
String i = "unknown";
curInfoPoint.put(currentAction, i);
}
logWriter.record("historyInfoPoint:" + chatCache.getInfoPoint().toString(), 1);
return debugFlag;
}
public boolean postprocessing(String chatKey, ServletContext context, Solution bestMatch){
if(chatCache.getInfoPoint().get("error_message") != null && chatCache.getInfoPoint().get("error_message") != ""){
bestMatch.setAnswer(bestMatch.getAnswer() + chatCache.getInfoPoint().get("error_message"));
}
return true;
}
/**
* 从当前信息点或者已知信息点中提取关键词
* @param infoPoint
* @param infoPoint2
* @param chooseLater
* @param actionName
* @return
*/
public String getKeyword(Map<String, String> infoPoint, Map<String, String> 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;
};
/**
* 更新历史信息点中的某一个键值对
* @param variableName
* @param updateValue
*/
public void putKeyword(String variableName, String updateValue){
chatCache.getInfoPoint().put(variableName, updateValue);
}
public String knowledgeProcess(String variableName, String updateValue){
return updateValue;
}
/**
* 额外的更新操作
*/
public void extraOperation(Action ansAction, Solution solution) throws IOException {
}
//将文本中存在的变量槽位{npc_xxx}替换成变量值
public String varSlotReplace(String text){
String VARIABLE_REPLACE_PATTERN = "(\\{.*?\\-[12]\\})";
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);
if (m.group(1).endsWith("-1}")) {
if (curInfoPoint.get(variable) != null && !curInfoPoint.get(variable).equals("")) {
keyword = curInfoPoint.get(variable);
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;
}
}
package com.qiwu.chatbotbackend.task.utils;
import com.qiwu.chatbotbackend.entity.Action;
import com.qiwu.chatbotbackend.entity.ChatCache;
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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class BasicBotUtil {
Map<String, String> curInfoPoint = null;
UserInfo userinfo = null;
LogWriter logWriter = null;
ChatCache chatCache = null;
public String botType = "basic";
public ChatCache getChatCache() {
return chatCache;
}
public BasicBotUtil(){};
public BasicBotUtil(Map<String, String> curInfoPoint, ChatCache chatCache, UserInfo userinfo, LogWriter logWriter){
this.curInfoPoint = curInfoPoint;
this.userinfo = userinfo;
this.logWriter = logWriter;
this.chatCache = chatCache;
}
public boolean preprocessing(Map<String, String[]> receiveParameters, ServletContext context) throws IOException {
return infoPointPreprocessing(receiveParameters, context, true);
}
//在接收到请求后对数据做处理,转化为系统可以处理的数据
/**
*
* @param receiveParameters
* @param context
* @param setUnknown 如果什么都没识别到就将上一个激活的condition设为unknown
* @return
* @throws IOException
*/
public boolean infoPointPreprocessing(Map<String, String[]> receiveParameters, ServletContext context, Boolean setUnknown) throws IOException {
String return_str = "", k, botType = "";
String receiveParameterStr = "";
boolean debugFlag = false;
HashSet<String> skipSet = new HashSet<String>() {
{
add("chat_key");
add("randKey");
add("userKey");
add("action_name");
add("bot_name");
add("emptySet");
add("query_text");
}
};
//输出所有actionName的值
Iterator<String> iit = receiveParameters.keySet().iterator();
receiveParameterStr+= "-----------------------------------------识别数据列表-------------------------------------------<br>";
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);
receiveParameterStr += values[0] + " " + "<br>";
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 = setUnknown;
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 (chatCache.getInfoPoint().containsKey("currentAction"))
currentAction = chatCache.getInfoPoint().get("currentAction");
else if (userinfo.extraInfo.containsKey("activeAction")) {
currentAction = userinfo.extraInfo.get("activeAction");
chatCache.getInfoPoint().put("currentAction", currentAction);
} else
currentAction = " ";
curInfoPoint.put("emptySet", " ");
if (chatCache.getInfoPoint().get("activeList") == null) {
chatCache.getInfoPoint().put("activeList", currentAction);
}
if (unknown_flag && !currentAction.equals("")) {
String i = "unknown";
curInfoPoint.put(currentAction, i);
}
// 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()) {
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);
return debugFlag;
}
public boolean postprocessing(String chatKey, ServletContext context, Solution bestMatch){
if(chatCache.getInfoPoint().get("error_message") != null && chatCache.getInfoPoint().get("error_message") != ""){
bestMatch.setAnswer(bestMatch.getAnswer() + chatCache.getInfoPoint().get("error_message"));
}
return true;
}
/**
* 从当前信息点或者已知信息点中提取关键词
* @param infoPoint
* @param infoPoint2
* @param chooseLater
* @param actionName
* @return
*/
public String getKeyword(Map<String, String> infoPoint, Map<String, String> 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;
};
/**
* 更新历史信息点中的某一个键值对
* @param variableName
* @param updateValue
*/
public void putKeyword(String variableName, String updateValue){
chatCache.getInfoPoint().put(variableName, updateValue);
}
public String knowledgeProcess(String variableName, String updateValue){
return updateValue;
}
/**
* 额外的更新操作
*/
public void extraOperation(Action ansAction, Solution solution) throws IOException {
}
//将文本中存在的变量槽位{npc_xxx}替换成变量值
public String varSlotReplace(String text){
String VARIABLE_REPLACE_PATTERN = "(\\{.*?\\-[12]\\})";
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);
if (m.group(1).endsWith("-1}")) {
if (curInfoPoint.get(variable) != null && !curInfoPoint.get(variable).equals("")) {
keyword = curInfoPoint.get(variable);
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