From 778bd62c3797e8a28b5537159dd2890ca679fa2a Mon Sep 17 00:00:00 2001 From: hxw Date: Fri, 14 Sep 2018 15:08:35 +0800 Subject: [PATCH] update --- src/processing/ProcessQuestion.java | 65 ++++++++++++++++++++++++++++++++++++++++++++++++----------------- src/servlet/GetAnswerServlet.java | 2 +- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/src/processing/ProcessQuestion.java b/src/processing/ProcessQuestion.java index 4f6fa67..e4f73b4 100644 --- a/src/processing/ProcessQuestion.java +++ b/src/processing/ProcessQuestion.java @@ -108,8 +108,6 @@ public class ProcessQuestion { public static Condition buildCondition(Condition condition,String line){ - //System.out.println("build condition"); - //System.out.println("xxxxx"+line); String feature,element[],pair[],next[],cur_premises[],history_premises[],premises[],firstCnditionName; line = line.split("---")[0]; @@ -260,6 +258,11 @@ public class ProcessQuestion { System.out.print(v + " "); } System.out.println(); + if(values[0].equals(":")){ + values[0] = ""; + curInfoPoint.put(k, values); + } + } //如果引擎什么信息都没识别到,那就将上一轮的nextStep(也就是当前轮的actionName)设为unknown @@ -479,7 +482,6 @@ public class ProcessQuestion { } else if (cmpType.equals("timeEarly")){ long candidateA,candidateB = 0; - System.out.println("1这里是:"+keyword); candidateA = MyFunc.transferToMillisecond(keyword); for(String k: keywordSet){ @@ -492,7 +494,6 @@ public class ProcessQuestion { } else if (cmpType.equals("timeLater")){ long candidateA,candidateB = 0; - System.out.println("1这里是:"+keyword); candidateA = MyFunc.transferToMillisecond(keyword); for(String k: keywordSet){ @@ -567,6 +568,7 @@ public class ProcessQuestion { try { + /* String keyword1, keyword2; while (it.hasNext()) { actionName = it.next(); @@ -579,6 +581,21 @@ public class ProcessQuestion { ans.setAnswer(ans.getAnswer().replace("{" + actionName + "-1}", keyword1));//这里 } } + */ + + it = historyInfoPoint.keySet().iterator(); + String keyword1, keyword2; + while (it.hasNext()) { + actionName = it.next(); + if(curInfoPoint.get(actionName) != null) { + keyword1 = curInfoPoint.get(actionName)[0]; + ans.setAnswer(ans.getAnswer().replace("{" + actionName + "-1}", keyword1));//这里 + } + + keyword2 = historyInfoPoint.get(actionName); + ans.setAnswer(ans.getAnswer().replace("{" + actionName + "-2}", keyword2)); + + } }catch(Exception e){ e.printStackTrace(); @@ -587,18 +604,23 @@ public class ProcessQuestion { return ans; } - public void infoTransition(Map curInfoPoint,Map historyInfoPoint, AnswerNextStep ans, ServletContext context){ + public void infoTransition(Map curInfoPoint,Map historyInfoPoint, AnswerNextStep ans, ServletContext context, boolean debugFlag){ //将当前信息点更新至历史信息点,并且替换答案中的相应变量,变量结构为{xxx-1}或者{xxx-2} Iterator it = curInfoPoint.keySet().iterator(); - String actionName; + String actionName, lastReply; String next = ans.getNext().split("=")[1]; //保存即将跳转的action名以供下一轮使用,nextStep的结构是nextStep=xxx historyInfoPoint.put("currentAction",next); historyInfoPoint.put("activeList", historyInfoPoint.get("activeList") + "|" + next); - try { + if(debugFlag) + lastReply = ans.getAnswer().split(")")[2]; + else + lastReply = ans.getAnswer(); + historyInfoPoint.put("lastReply", lastReply); + try { String keyword1, keyword2; while (it.hasNext()) { actionName = it.next(); @@ -612,6 +634,23 @@ public class ProcessQuestion { } + /* + // 根据hisInfoPoint中的key来更新历史信息,前提是在关键词单元不加simple_post + it = historyInfoPoint.keySet().iterator(); + String keyword1, keyword2; + while (it.hasNext()) { + actionName = it.next(); + if(curInfoPoint.get(actionName) != null){ + keyword1 = curInfoPoint.get(actionName)[0]; + keyword2 = historyInfoPoint.get(actionName); + if(! keyword2.equals("")){ + historyInfoPoint.put(actionName, keyword1); + } + } + + } + */ + ChatCacheController.updateChatCache4Insert(curInfoPoint, historyInfoPoint, context); //context.setAttribute("chat_key+"+userinfo.userName,historyInfoPoint); @@ -635,6 +674,7 @@ public class ProcessQuestion { add("bot_name"); add("action_name"); add("chat_key"); + add("lastReply"); } }; @@ -657,7 +697,7 @@ public class ProcessQuestion { debugInfo += (" " + key + ":" + value + " "); } - ans.setAnswer( debugInfo + ")" + ans.getAnswer()); + ans.setAnswer( debugInfo + ")" + ans.getAnswer()); } @@ -672,7 +712,6 @@ public class ProcessQuestion { List pairList = new ArrayList(); Iterator k_iter = null; - System.out.println("there"); for(String feature:features){ elem = feature.split("\\("); if(elem[0].contains("post")){ @@ -823,8 +862,6 @@ public class ProcessQuestion { if (feature.contains("updateKnowledge")){ for (String knowledge: feature.split("-<-")){ pair = knowledge.split(":"); - System.out.println("knowledge"+knowledge); - System.out.println(pair.length); keyword = historyInfoPoint.get(pair[0]); if(pair.length > 1) { @@ -833,7 +870,6 @@ public class ProcessQuestion { if(keyword == null || keyword.equals("")) keyword = "0"; if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) { - System.out.println("这里是keyword:" + keyword); long time = MyFunc.transferToMillisecond(keyword); int offset = Integer.parseInt(pair[1].substring(1)); pair[1] = MyFunc.transferToStandardTime(time + (1000 * offset)); @@ -841,18 +877,15 @@ public class ProcessQuestion { int number = Integer.parseInt(keyword); int offset = Integer.parseInt(pair[1].substring(1)); pair[1] = String.valueOf(number + offset); - System.out.println("加一:"+pair[1]); } } else if (pair[1].startsWith("-")) { if(keyword == null || keyword.equals("")) keyword = "0"; if (keyword.matches("\\d{4}年\\d{1,2}月\\d{1,2}日.*")) { - System.out.println("这里是keyword:" + keyword); long time = MyFunc.transferToMillisecond(keyword); int offset = Integer.parseInt(pair[1].substring(1)); pair[1] = MyFunc.transferToStandardTime(time - (1000 * offset)); - System.out.println("改变后:"+ pair[1]); }else if (StringUtils.isNumeric(keyword)){ int number = Integer.parseInt(keyword); int offset = Integer.parseInt(pair[1].substring(1)); @@ -865,9 +898,7 @@ public class ProcessQuestion { } else if (pair[1].startsWith("str-")) { if(keyword == null || keyword.equals("")) keyword = ""; - System.out.println("aa"); pair[1] = keyword.replace(pair[1].substring(4), ""); - System.out.println(pair[1]); } }catch (Exception e){ e.printStackTrace(); diff --git a/src/servlet/GetAnswerServlet.java b/src/servlet/GetAnswerServlet.java index b49ff3d..2bc56f5 100644 --- a/src/servlet/GetAnswerServlet.java +++ b/src/servlet/GetAnswerServlet.java @@ -98,7 +98,7 @@ public class GetAnswerServlet extends HttpServlet { process.appendDebugInfo(bestMatch, curInfoPoint, historyInfoPoint, context); } - process.infoTransition(curInfoPoint, historyInfoPoint, bestMatch, context); + process.infoTransition(curInfoPoint, historyInfoPoint, bestMatch, context, debugFlag); ansJ = MyFunc.toJson(bestMatch); -- libgit2 0.27.1