Commit 98a7786c by 赵国君

快速开始

parent 04bd4be9
package com.qiwu.chatbotbackend.GameEnvironment;
public class Test {
public static void main(String[] args) throws Exception {
GameEnv gameEnv = new GameEnv("7011489633");
// System.out.println(gameEnv.queryNpcAttrByNpcName("武士", "热度"));
System.out.println(gameEnv.queryGlobalAttr("啦啦"));
}
}
...@@ -52,16 +52,17 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -52,16 +52,17 @@ public class PlotConstructor2 extends ElementConstructor {
} }
public void construct(JSONObject jsonObject, UserInfo userinfo) { public void construct(JSONObject jsonObject, UserInfo userinfo) {
Integer startOption = jsonObject.getInteger("startOption");
try { try {
addGameStartPlot(jsonObject, keywordMap); if(startOption != null && startOption.equals(2)) {
} else {
addGameStartPlot(jsonObject, keywordMap);
}
JSONArray plots = jsonObject.getJSONArray("plots"); JSONArray plots = jsonObject.getJSONArray("plots");
String start = (String) jsonObject.get("start"), startCondition; String start = (String) jsonObject.get("start"), startCondition;
JSONObject returnMessage = null; JSONObject returnMessage = null;
this.plots = plots; this.plots = plots;
constructAdjList(plots); constructAdjList(plots);
...@@ -737,10 +738,7 @@ public class PlotConstructor2 extends ElementConstructor { ...@@ -737,10 +738,7 @@ public class PlotConstructor2 extends ElementConstructor {
jsonStr = jsonStr.replace("startId", gameElements.getString("start")); jsonStr = jsonStr.replace("startId", gameElements.getString("start"));
jsonStr = jsonStr.replace("site_list", keywordMap.get("site_list").toString()); jsonStr = jsonStr.replace("site_list", keywordMap.get("site_list").toString());
//System.out.println("JSONSTR ------------------------------\n" + jsonStr);
JSONObject config = JSONObject.parseObject(jsonStr); JSONObject config = JSONObject.parseObject(jsonStr);
gameElements.getJSONArray("plots").addAll(config.getJSONArray("gameStart")); gameElements.getJSONArray("plots").addAll(config.getJSONArray("gameStart"));
gameElements.put("start", "start1"); gameElements.put("start", "start1");
gameElements.put("firstUnknownText", GAME_START_HINT); gameElements.put("firstUnknownText", GAME_START_HINT);
......
...@@ -829,7 +829,7 @@ public class ActionMatcher { ...@@ -829,7 +829,7 @@ public class ActionMatcher {
poster.postTerm(curInfoPoint, historyInfoPoint, ans, ansAction, url); poster.postTerm(curInfoPoint, historyInfoPoint, ans, ansAction, url);
}else if(postType.equals("gameQA")){ }else if(postType.equals("gameQA")){
System.out.println("提交表单" + gameEnv); System.out.println("提交表单" + gameEnv);
poster.postGameQA(curInfoPoint, historyInfoPoint, ans, gameEnv, worldController, url, userinfo); poster.postGameQA(curInfoPoint, historyInfoPoint, ans, gameEnv, worldController, url, userinfo);
} }
return ans; return ans;
......
package com.qiwu.chatbotbackend.servlet; package com.qiwu.chatbotbackend.servlet;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.actiongenerate.DB.EngineUtils; import com.qiwu.chatbotbackend.actiongenerate.DB.EngineUtils;
import com.qiwu.chatbotbackend.actiongenerate.entity.IntervalStatus; import com.qiwu.chatbotbackend.actiongenerate.entity.IntervalStatus;
import com.qiwu.chatbotbackend.actiongenerate.utils.ActionUtils; import com.qiwu.chatbotbackend.actiongenerate.utils.ActionUtils;
import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.ConfigTermText; import com.qiwu.chatbotbackend.entity.ConfigTermText;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.gameDesign.*; import com.qiwu.chatbotbackend.gameDesign.*;
import com.qiwu.chatbotbackend.processing.ChatCacheController; import com.qiwu.chatbotbackend.processing.ChatCacheController;
import com.qiwu.chatbotbackend.processing.SimpleUtil; import com.qiwu.chatbotbackend.processing.SimpleUtil;
import com.qiwu.chatbotbackend.processing.UserInfoController; import com.qiwu.chatbotbackend.processing.UserInfoController;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet; import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import static com.qiwu.chatbotbackend.Config.Config.*; import static com.qiwu.chatbotbackend.Config.Config.*;
@WebServlet(name = "GameDesignServlet", urlPatterns = {"/gameDesign"}) @WebServlet(name = "GameDesignServlet", urlPatterns = {"/gameDesign"})
public class GameDesignServlet extends HttpServlet { public class GameDesignServlet extends HttpServlet {
//分组及其相应的id,id初始化为0, 新建分组成功后id会更新。 //分组及其相应的id,id初始化为0, 新建分组成功后id会更新。
HashMap<String, Integer> categoryMap = new HashMap<String, Integer>(){ HashMap<String, Integer> categoryMap = new HashMap<String, Integer>(){
{ {
put("地图", 0); put("地图", 0);
put("剧情", 0); put("剧情", 0);
put("物品", 0); put("物品", 0);
put("NPC", 0); put("NPC", 0);
put("全局变量", 0); put("全局变量", 0);
} }
}; };
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
DateTimeFormatter dtf=DateTimeFormatter.ofPattern("MM-dd HH:mm:ss.SSS"); DateTimeFormatter dtf=DateTimeFormatter.ofPattern("MM-dd HH:mm:ss.SSS");
StringBuffer timeUsedDetect = new StringBuffer(); StringBuffer timeUsedDetect = new StringBuffer();
LocalDateTime ldt = LocalDateTime.now(); LocalDateTime ldt = LocalDateTime.now();
String now = ldt.format(dtf); String now = ldt.format(dtf);
timeUsedDetect.append("接收请求的时间:").append(now); timeUsedDetect.append("接收请求的时间:").append(now);
//所有需要修改的词性 //所有需要修改的词性
StringBuffer POS = new StringBuffer(); StringBuffer POS = new StringBuffer();
//每个condition的三元组两端需要补充的关键词,比如npc名字、npc属性等,格式为: "conditionName_tail/head":"keywords" //每个condition的三元组两端需要补充的关键词,比如npc名字、npc属性等,格式为: "conditionName_tail/head":"keywords"
HashMap<String, HashSet<String>> additionalKeywords = new HashMap<String, HashSet<String>>(); HashMap<String, HashSet<String>> additionalKeywords = new HashMap<String, HashSet<String>>();
//预先定义好的所有condition相关的关键词,格式为 "conditionName_标签":"keywords" //预先定义好的所有condition相关的关键词,格式为 "conditionName_标签":"keywords"
Map<String, StringBuffer> keywordMap = new HashMap<String, StringBuffer>(); Map<String, StringBuffer> keywordMap = new HashMap<String, StringBuffer>();
//特定的relation的三元组不会被添加到relationKeywords //特定的relation的三元组不会被添加到relationKeywords
HashSet<String> exceptRelation = new HashSet<String>(); HashSet<String> exceptRelation = new HashSet<String>();
Integer botId, projectId, dataId, returnStatus = 1; Integer botId, projectId, dataId, returnStatus = 1;
String botAccount = null, userName, botName, moduleName2, returnMessage = "Success"; String botAccount = null, userName, botName, moduleName2, returnMessage = "Success";
ServletContext context = this.getServletContext(); ServletContext context = this.getServletContext();
JSONObject json = null, root = null; JSONObject json = null, root = null;
Boolean flag; Boolean flag;
SqlHelper helper = null; SqlHelper helper = null;
List<Integer> idList = new ArrayList<>(); List<Integer> idList = new ArrayList<>();
ElementConstructor constructor = new ElementConstructor(); ElementConstructor constructor = new ElementConstructor();
try { try {
helper = new SqlHelper(); helper = new SqlHelper();
//读取并解析json数据 //读取并解析json数据
String jsonStr = SimpleUtil.readJSONString(request); String jsonStr = SimpleUtil.readJSONString(request);
if (jsonStr != null && !jsonStr.equals("")) { if (jsonStr != null && !jsonStr.equals("")) {
JSONObject receiveParaneters = JSONObject.parseObject(jsonStr); JSONObject receiveParaneters = JSONObject.parseObject(jsonStr);
dataId = (Integer) receiveParaneters.get("id"); dataId = (Integer) receiveParaneters.get("id");
JSONObject gameElements = helper.queryGameElementsByProjectId(dataId); JSONObject gameElements = helper.queryGameElementsByProjectId(dataId);
gameElements.put("auth", request.getHeader("authorization")); gameElements.put("auth", request.getHeader("authorization"));
//System.out.println(gameElements.toJSONString()); //System.out.println(gameElements.toJSONString());
botId = (Integer)gameElements.get("botId"); botId = (Integer)gameElements.get("botId");
botAccount = (String) gameElements.get("botAccount"); botAccount = (String) gameElements.get("botAccount");
userName = (String)gameElements.get("userName"); userName = (String)gameElements.get("userName");
botName = (String)gameElements.get("botName"); botName = (String)gameElements.get("botName");
//假设重建用户信息 //假设重建用户信息
if (context.getAttribute(botAccount) == null) { if (context.getAttribute(botAccount) == null) {
UserInfoController.userConfigInit(botAccount, context); UserInfoController.userConfigInit(botAccount, context);
} }
UserInfo userinfo = (UserInfo) context.getAttribute(botAccount); UserInfo userinfo = (UserInfo) context.getAttribute(botAccount);
//清空之前生成的配置条目 //清空之前生成的配置条目
flag = botInit(botId, botAccount, userinfo, helper, context); flag = botInit(botId, botAccount, userinfo, helper, context);
StringBuffer mergedConfigText = new StringBuffer(); StringBuffer mergedConfigText = new StringBuffer();
int skipCount = 0; int skipCount = 0;
//从文件中读取condition相关的关键词 //从文件中读取condition相关的关键词
readKeywords(keywordMap, KEYWORD_DIR); readKeywords(keywordMap, KEYWORD_DIR);
// ldt = LocalDateTime.now(); // ldt = LocalDateTime.now();
// now = ldt.format(dtf); // now = ldt.format(dtf);
// timeUsedDetect.append("\n,预处理之后:").append(now); // timeUsedDetect.append("\n,预处理之后:").append(now);
String moduleList[] = {"map", "goods", "globalVariable", "npc", "plots"}; String moduleList[] = {"map", "goods", "globalVariable", "npc", "plots"};
for(String moduleName: moduleList){ for(String moduleName: moduleList){
switch (moduleName) { switch (moduleName) {
case "map": case "map":
moduleName2 = "地图"; moduleName2 = "地图";
constructor = new MapConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS); constructor = new MapConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
case "plots": case "plots":
moduleName2 = "剧情"; moduleName2 = "剧情";
constructor = new PlotConstructor2(helper, botId, botAccount, keywordMap, exceptRelation, POS); constructor = new PlotConstructor2(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
root = ((PlotConstructor2) constructor).getPlotIndex().get((String) gameElements.get("start")); root = ((PlotConstructor2) constructor).getPlotIndex().get((String) gameElements.get("start"));
break; break;
case "goods": case "goods":
moduleName2 = "物品"; moduleName2 = "物品";
constructor = new ItemConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS); constructor = new ItemConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
case "globalVariable": case "globalVariable":
moduleName2 = "全局变量"; moduleName2 = "全局变量";
constructor = new GlobalVariableConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS); constructor = new GlobalVariableConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
case "npc": case "npc":
moduleName2 = "NPC"; moduleName2 = "NPC";
constructor = new CharacterConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS); constructor = new CharacterConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
default: default:
continue; continue;
} }
if (constructor.getOperationStatus() == 1) { if (constructor.getOperationStatus() == 1) {
//先清空再插入 //先清空再插入
idList.clear(); idList.clear();
helper.batchInsertVariableByBotId(botId, constructor); helper.batchInsertVariableByBotId(botId, constructor);
List<JSONObject> jsonList = new ArrayList<JSONObject>(); List<JSONObject> jsonList = new ArrayList<JSONObject>();
for(ConfigTermText configTermText : constructor.getConfigTermTextList()){ for(ConfigTermText configTermText : constructor.getConfigTermTextList()){
json = configTermText.toJson(constructor.getConditionDescription()); json = configTermText.toJson(constructor.getConditionDescription());
constructor.parseKeyword(json, additionalKeywords, exceptRelation, botName); constructor.parseKeyword(json, additionalKeywords, exceptRelation, botName);
jsonList.add(json); jsonList.add(json);
} }
helper.batchInsertConfigByBotId(botId, jsonList, idList, categoryMap.get(moduleName2));
constructor.postProcessing(idList, categoryMap.get(moduleName2));
constructor.generateConfigText(idList);
helper.batchInsertConfigByBotId(botId, jsonList, idList, categoryMap.get(moduleName2));
constructor.postProcessing(idList, categoryMap.get(moduleName2)); mergedConfigText.append(constructor.getConfigText());
constructor.generateConfigText(idList); }else {
returnStatus = 0;
mergedConfigText.append(constructor.getConfigText()); returnMessage = constructor.getMessage();
}else { break;
returnStatus = 0; }
returnMessage = constructor.getMessage();
break; ldt = LocalDateTime.now();
} now = ldt.format(dtf);
timeUsedDetect.append("\n,").append(moduleName2).append("模块:").append(now);
ldt = LocalDateTime.now();
now = ldt.format(dtf); }
timeUsedDetect.append("\n,").append(moduleName2).append("模块:").append(now);
if(returnStatus == 1) {
} StringReader sr = new StringReader(mergedConfigText.toString());
BufferedReader br = new BufferedReader(sr);
if(returnStatus == 1) { UserInfoController.buildUserInfo(br, userinfo, true);
// ldt = LocalDateTime.now(); context.setAttribute(botAccount, userinfo);
// now = ldt.format(dtf); IntervalStatus generateResult = actionRegenerate(root, gameElements, userinfo, additionalKeywords, exceptRelation, POS, helper);
// timeUsedDetect.append("\n发送post请求预处理:").append(now); UserInfoController.writeConfigText(botAccount, userinfo);
StringReader sr = new StringReader(mergedConfigText.toString());
BufferedReader br = new BufferedReader(sr); if(generateResult.getStatus() != 1){
//System.out.println(mergedConfigText.toString()); returnStatus = 0;
UserInfoController.buildUserInfo(br, userinfo, true); returnMessage = generateResult.getMessage();
context.setAttribute(botAccount, userinfo); }
UserInfoController.writeConfigText(botAccount, userinfo); }
// ldt = LocalDateTime.now();
// now = ldt.format(dtf);
// timeUsedDetect.append("\n发送post请求前:").append(now); }else {
IntervalStatus generateResult = actionRegenerate(root, gameElements, userinfo, additionalKeywords, exceptRelation, POS, helper); returnStatus = 0;
returnMessage = "请求解析失败";
// ldt = LocalDateTime.now(); }
// now = ldt.format(dtf); } catch (SQLException e) {
// timeUsedDetect.append("\n发送post请求后:").append(now); e.printStackTrace();
} finally{
if(generateResult.getStatus() != 1){ helper.destroy();
returnStatus = 0; }
returnMessage = generateResult.getMessage();
}
}
System.out.println(timeUsedDetect.toString());
}else {
returnStatus = 0; JSONObject responseJSONObject = new JSONObject();
returnMessage = "请求解析失败"; responseJSONObject.put("status", returnStatus);
} responseJSONObject.put("message", returnMessage);
} catch (SQLException e) { response.setCharacterEncoding("UTF-8");
e.printStackTrace(); response.setContentType("application/json; charset=utf-8");
} finally{
helper.destroy();
}
System.out.println("xx:" + responseJSONObject.toJSONString());
System.out.println(timeUsedDetect.toString());
PrintWriter out = response.getWriter();
out.append(responseJSONObject.toString());
JSONObject responseJSONObject = new JSONObject(); out.flush();
responseJSONObject.put("status", returnStatus);
responseJSONObject.put("message", returnMessage); }
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
OutputStream out = response.getOutputStream();
System.out.println("xx:" + responseJSONObject.toJSONString()); out.write("ssss".getBytes());
out.flush();
}
PrintWriter out = response.getWriter(); public boolean botInit(int botId, String botAccount, UserInfo userInfo, SqlHelper helper, ServletContext context) throws SQLException, IOException {
out.append(responseJSONObject.toString()); boolean deleteConfigFlag = helper.deleteConfigByBotId(botId);
out.flush(); boolean deleteVariableFlag = helper.deleteVariableByBotId(botId);
} boolean deleteCategoryFlag = helper.deleteCategoryByBotId(botId);
boolean insertCategoryFlag = helper.batchInsertCategoryByBotId(botId, categoryMap);
boolean deteteConditionFlag = helper.deleteConditionByBotId(botId);
boolean deleteArchiveFlag = ChatCacheController.deleteChatCache(helper, botAccount, context);
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
OutputStream out = response.getOutputStream();
out.write("ssss".getBytes()); return deleteConfigFlag && deleteVariableFlag;
out.flush(); }
}
public boolean botInit(int botId, String botAccount, UserInfo userInfo, SqlHelper helper, ServletContext context) throws SQLException, IOException { /**
boolean deleteConfigFlag = helper.deleteConfigByBotId(botId); * 重新生成action文本
boolean deleteVariableFlag = helper.deleteVariableByBotId(botId); * @param root
* @param gameElements
boolean deleteCategoryFlag = helper.deleteCategoryByBotId(botId); * @param userInfo
boolean insertCategoryFlag = helper.batchInsertCategoryByBotId(botId, categoryMap); * @param additionalKeywords
boolean deteteConditionFlag = helper.deleteConditionByBotId(botId); * @param exceptRelation
boolean deleteArchiveFlag = ChatCacheController.deleteChatCache(helper, botAccount, context); * @param POS
* @return
*/
return deleteConfigFlag && deleteVariableFlag; public IntervalStatus actionRegenerate(JSONObject root, JSONObject gameElements, UserInfo userInfo, HashMap<String, HashSet<String>> additionalKeywords, HashSet<String> exceptRelation, StringBuffer POS, SqlHelper helper){
} String startCondition, POS2 = "", botName = gameElements.getString("botName");
System.out.println(botName);
Integer startOption = gameElements.getInteger("startOption");
/** JSONObject returnMessage = null;
* 重新生成action文本 EngineUtils engine = null;
* @param root IntervalStatus intervalStatus = new IntervalStatus(1, "");
* @param gameElements
* @param userInfo JSONObject actionPostData = new JSONObject();
* @param additionalKeywords
* @param exceptRelation startCondition = (String)root.get("conditionName");
* @param POS actionPostData.put("startCondition", "start_options");
* @return if(startOption != null && startOption.equals(2)) {
*/ actionPostData.put("welcome", gameElements.getString("plotStartText"));
public IntervalStatus actionRegenerate(JSONObject root, JSONObject gameElements, UserInfo userInfo, HashMap<String, HashSet<String>> additionalKeywords, HashSet<String> exceptRelation, StringBuffer POS, SqlHelper helper){ } else {
String startCondition, POS2 = "", botName = gameElements.getString("botName"); actionPostData.put("welcome", String.format(GAME_WELCOME_TEXT, botName));
System.out.println(botName); }
JSONObject returnMessage = null; actionPostData.put("relationKeywords", additionalKeywords);
EngineUtils engine = null; actionPostData.put("botId", gameElements.getInteger("botId"));
IntervalStatus intervalStatus = new IntervalStatus(1, "");
if(gameElements.getJSONArray("conditionCategories") != null){
JSONObject actionPostData = new JSONObject(); actionPostData.put("conditionCategories", gameElements.getJSONArray("conditionCategories"));
}else{
startCondition = (String)root.get("conditionName"); actionPostData.put("conditionCategories", new JSONArray(){
actionPostData.put("startCondition", "start_options"); {
actionPostData.put("welcome", String.format(GAME_WELCOME_TEXT, gameElements.getString("botName"))); add(GAME_CONDITION_CATEGORY);
actionPostData.put("relationKeywords", additionalKeywords); }
actionPostData.put("botId", gameElements.getInteger("botId")); });
}
if(gameElements.getJSONArray("conditionCategories") != null){
actionPostData.put("conditionCategories", gameElements.getJSONArray("conditionCategories"));
}else{
actionPostData.put("conditionCategories", new JSONArray(){ if (gameElements.containsKey("POS"))
{ POS2 = (String)gameElements.get("POS");
add(GAME_CONDITION_CATEGORY); actionPostData.put("POS", POS.toString() + POS2);
}
}); System.out.println(actionPostData.toJSONString());
}
try {
engine = new EngineUtils();
ActionUtils actionUtils = new ActionUtils(engine, helper);
if (gameElements.containsKey("POS")) actionUtils.gamePlotInit(botName, gameElements.getInteger("botId"), gameElements.getString("auth"), actionPostData, startCondition, additionalKeywords);
POS2 = (String)gameElements.get("POS"); intervalStatus = actionUtils.intervalStatus;
actionPostData.put("POS", POS.toString() + POS2); }catch(Exception e){
e.printStackTrace();
System.out.println(actionPostData.toJSONString()); intervalStatus = new IntervalStatus(0, "action生成失败");
}finally {
try { engine.destroy();
engine = new EngineUtils(); }
ActionUtils actionUtils = new ActionUtils(engine, helper);
actionUtils.gamePlotInit(botName, gameElements.getInteger("botId"), gameElements.getString("auth"), actionPostData, startCondition, additionalKeywords); userInfo.extraInfo.put("activeAction", startCondition);
intervalStatus = actionUtils.intervalStatus;
}catch(Exception e){ return intervalStatus;
e.printStackTrace();
intervalStatus = new IntervalStatus(0, "action生成失败"); }
}finally {
engine.destroy();
} //从配置文件中读取生成状态表所需要的关键词
public void readKeywords(Map<String, StringBuffer> keywordsMap, String path){
userInfo.extraInfo.put("activeAction", startCondition);
File file = new File(path);
return intervalStatus; String line, elem[];
} if(file.exists()){
FileReader reader = null;
try {
//从配置文件中读取生成状态表所需要的关键词 reader = new FileReader(file);
public void readKeywords(Map<String, StringBuffer> keywordsMap, String path){ BufferedReader br = new BufferedReader(reader);
File file = new File(path);
String line, elem[]; while ((line = br.readLine()) != null) {
if(!line.equals("") && !line.startsWith("#")) {
if(file.exists()){ elem = line.split("\\|", 3);
FileReader reader = null;
try { //查看意图是否已经存在相关的condition,如果已经存在就append,如果不存在就初始化
reader = new FileReader(file); if (!elem[1].equals("pattern")) {
BufferedReader br = new BufferedReader(reader); if (keywordsMap.get(elem[0]) == null) {
keywordsMap.put(elem[0], new StringBuffer(elem[1]));
} else {
while ((line = br.readLine()) != null) { keywordsMap.get(elem[0]).append(",").append(elem[1]);
if(!line.equals("") && !line.startsWith("#")) { }
elem = line.split("\\|", 3); }
//查看意图是否已经存在相关的condition,如果已经存在就append,如果不存在就初始化 //根据意图和condition名字添加关键字
if (!elem[1].equals("pattern")) { keywordsMap.put(elem[0] + "_" + elem[1], new StringBuffer(elem[2]));
if (keywordsMap.get(elem[0]) == null) {
keywordsMap.put(elem[0], new StringBuffer(elem[1])); }
} else {
keywordsMap.get(elem[0]).append(",").append(elem[1]); }
} } catch (FileNotFoundException e) {
} e.printStackTrace();
} catch (IOException e) {
//根据意图和condition名字添加关键字 e.printStackTrace();
keywordsMap.put(elem[0] + "_" + elem[1], new StringBuffer(elem[2])); }
} }
}
}
} catch (FileNotFoundException e) {
e.printStackTrace(); }
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
package com.qiwu.chatbotbackend.servlet; package com.qiwu.chatbotbackend.servlet;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.actiongenerate.DB.EngineUtils;
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;
...@@ -17,6 +18,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -17,6 +18,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.sql.SQLException;
import java.text.ParseException; import java.text.ParseException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -44,11 +46,29 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -44,11 +46,29 @@ public class GetAnswerServlet extends HttpServlet {
if(tmpStr == null || tmpStr.equals("")) if(tmpStr == null || tmpStr.equals(""))
continue; continue;
tmpStr = tmpStr.replace("qiwu", "我"); tmpStr = tmpStr.replace("qiwu", "我");
//tmpStr = tmpStr.replace("qiwu", "你");
receiveParamters.put(entry.getKey(), tmpStr); receiveParamters.put(entry.getKey(), tmpStr);
} }
} }
String botName = receiveParamters.get("bot_name"); String botName = receiveParamters.get("bot_name");
/*
EngineUtils engineDBConn = null;
try {
engineDBConn = new EngineUtils();
String nickname = engineDBConn.queryBotNickNameByName(botName);
} catch (SQLException e1) {
e1.printStackTrace();
} finally {
engineDBConn.destroy();
}
Set<Entry<String, String>> entrySet2 = receiveParamters.entrySet();
for(Entry<String, String> entry : entrySet2) {
String value = entry.getValue();
if(value.indexOf("")) {
}
}
*/
Map<String ,String> curInfoPoint = new HashMap<String, String>(); Map<String ,String> curInfoPoint = new HashMap<String, String>();
Solution bestMatch = null; Solution bestMatch = null;
......
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