Commit 15fa3483 by hxw

routine

parent 1a3a09de
......@@ -69,6 +69,7 @@ public class ChatCache implements DisposableBean {
gameEnv = new GameEnv(userInfo.botAccount);
}catch (Exception e){
System.out.println("游戏平台初始化失败");
e.printStackTrace();
}
String k;
......
......@@ -443,7 +443,7 @@ public class JConfig implements Cloneable{
}
public static void activateCopy(JConfig jConfig, List<JConfig> jConfigList){
public static void activateCopy(JConfig jConfig, List<JConfig> jConfigList, String name){
jConfig.setReply(jConfig.getReply() + "{临时变量reply-2}");
......@@ -453,13 +453,13 @@ public class JConfig implements Cloneable{
jConfig.setHisPremise("临时变量condition::match-Include=+null");
else
jConfig.setHisPremise(jConfig.getjHisPremise() + ",临时变量condition::match-Include=+null");
jConfig.setConfigName("map", true);
jConfig.setConfigName(name, true);
if(jConfig2.getUpdateKnowledge().equals(""))
jConfig2.setUpdateKnowledge("process-nextStep:var={临时变量condition-2}");
else
jConfig2.setUpdateKnowledge(jConfig2.getUpdateKnowledge() + "-<-process-nextStep:var={临时变量condition-2}");
jConfig2.setConfigName("map", true);
jConfig2.setConfigName(name, true);
jConfigList.add(jConfig);
......
......@@ -10,13 +10,13 @@ import java.util.*;
public class CharacterConstructor extends ElementConstructor {
public CharacterConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet<String> exceptRelation, StringBuffer POS) {
public CharacterConstructor(SqlHelper helper, int botId, String botAccount, Map<String, StringBuffer> keywordMap, HashSet<String> exceptRelation, StringBuffer POS) {
super();
this.helper = helper;
this.botId = botId;
this.botAccount = botAccount;
this.exceptRelation = exceptRelation;
this.skipCount = skipCount;
this.keywordMap = keywordMap;
this.POS = POS;
}
......@@ -24,41 +24,45 @@ public class CharacterConstructor extends ElementConstructor {
String category, name, className, description, attrName, attrValue;
try {
String pattern1 = keywordMap.get("npc_location_pattern").toString();
JSONArray allNPC = gameElements.getJSONArray("npc");
Map<String, String> attribute = null;
Iterator<String> attrIter = null;
HashSet<String> classSet = new HashSet<String>();
//与npc属性相关的所有condition
ArrayList<String> relateConditions = new ArrayList<String>() {
{
add("wenzainali");
add("shishenme");
}
};
//与npc类相关的所有condition
ArrayList<String> classRelateConditions = new ArrayList<String>() {
{
add("know_exist_what");
}
};
keywordMap.putIfAbsent("npc_wenzainali", new StringBuffer());
keywordMap.putIfAbsent("npc_shishenme", new StringBuffer());
keywordMap.putIfAbsent("npc_know_exist_what", new StringBuffer());
keywordMap.putIfAbsent("npc_nums", new StringBuffer());
//与物品属性查询相关的所有condition
String attrRelateConditions[] = {"nums", "shishenme"};
//在condition的三元组中添加与NPC相关的关键词
//与物品类查询相关的所有condition
String classRelateConditions[] = {"know_exist_what" };
String locationRelateConditions[] = {"wenzainali"};
String conditionValue = "哪里:人称", repValue;
StringBuffer keywords = new StringBuffer();
//在condition的三元组中添加与NPC相关的关键词
StringBuffer classKeywords = new StringBuffer();
for (JSONObject character : allNPC.toJavaList(JSONObject.class)) {
name = (String) character.get("name");
//添加词性
if(!name.equals(""))
POS.append("=" + name + "|人名\r\n");
className = (String) character.get("class");
if(!className.equals(""))
POS.append("=" + className + "|人名\r\n");
//添加类名称
if (!classSet.contains(className)) {
classSet.add(className);
classKeywords.append("+周围:" + className + "+附近:" + className);
......@@ -67,46 +71,63 @@ public class CharacterConstructor extends ElementConstructor {
attribute = gameElements.toJavaObject(character.getJSONObject("attr"), Map.class);
attrIter = attribute.keySet().iterator();
repValue = conditionValue.replace("人称", name);
keywords.append("+" + repValue);
keywordMap.get("npc_" + locationRelateConditions[0]).append(pattern1.replace("name", name));
while (attrIter.hasNext()) {
attrName = attrIter.next();
if(!attrName.equals(""))
POS.append("=" + attrName + "|名词\r\n");
attrValue = attribute.get(attrName);
for(String condition: attrRelateConditions){
}
keywordMap.get("npc_" + condition).append("+" + attrName + ":" + attrValue);
}
System.out.println(name);
}
}
//根据根据NPC名字和属性查询属性值
for (String conditionName : relateConditions) {
//根据根据NPC的名字查询地点
for (String conditionName : locationRelateConditions) {
jConfig = new JConfig(
conditionName + "::match-Include=" + keywords, " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{NPC_query-2}", "yaobuyao", "NPC_query:queryAttrByNPCName:" + conditionName
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName
);
jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig);
JConfig.activateCopy(jConfig, jConfigList, "npc");
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName) + "," +
"zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName
);
JConfig.activateCopy(jConfig, jConfigList, "npc");
//jConfigList.add(jConfig);
}
//根据根据NPC名字和属性查询属性值
for(String conditionName: attrRelateConditions){
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao", "npc_query:queryAttrByNPCName:" + conditionName
);
JConfig.activateCopy(jConfig, jConfigList, "npc");
}
//根据根据NPC类别和地点属性查询所有NPC实例
for (String conditionName : relateConditions) {
for (String conditionName : classRelateConditions) {
jConfig = new JConfig(
conditionName + "::match-Include=" + classKeywords, " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{NPC_query-2}", "yaobuyao", "NPC_query:queryAroundNpcByClassName:" + conditionName
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao", "npc_query:queryAroundNpcByClassName:" + conditionName
);
jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig);
JConfig.activateCopy(jConfig, jConfigList, "npc");
//jConfigList.add(jConfig);
}
}catch (Exception e){
operationStatus = 0;
message = "NPC接口处理出现异常";
e.printStackTrace();
return;
}
}
......
......@@ -16,7 +16,7 @@ public class ElementConstructor {
int operationStatus = 1;
int skipCount = 0;
Map<String, StringBuffer> keywordMap = null;
SqlHelper helper = null;
HashSet<String> exceptRelation = null;
JConfig jConfig = null;
......@@ -97,13 +97,20 @@ public class ElementConstructor {
relationKeywords.put(conditionName + "_tail", new HashSet<String>());
}
premise.put("keywords", ((String)premise.get("keywords")).replace("qiwu", "#visitorname"));
for (String keyword : ((String) premise.get("keywords")).split("\\+")) {
if(keyword.equals("")){
continue;
} else if(keyword.contains(":")){
pair = keyword.split(":");
pair = keyword.split(":",2);
if(pair[1].equals(""))
continue;
relationKeywords.get(conditionName + "_head").add(pair[0]);
relationKeywords.get(conditionName + "_tail").add(pair[1]);
......
package com.qiwu.chatbotbackend.gameDesign;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import com.qiwu.chatbotbackend.processing.LogWriter;
import com.qiwu.chatbotbackend.processing.WorldController;
import java.util.Map;
public class GameUtil {
public GameEnv gameEnv = null;
public Map<String ,String> curInfoPoint = null;
public Map<String ,String> historyInfoPoint = null;
public WorldController worldController = null;
public GameUtil(GameEnv gameEnv, WorldController worldController, Map<String, String> curInfoPoint, Map<String, String> historyInfoPoint) {
this.gameEnv = gameEnv;
this.curInfoPoint = curInfoPoint;
this.historyInfoPoint = historyInfoPoint;
this.worldController = worldController;
}
public void gamePreprocessing(LogWriter logWriter){
//将要去的地点的别名替换为真名
String conditionList[] = {"yaobuyao", "want_know_zenmezuo"};
for(String conditionName: conditionList) {
if (!curInfoPoint.get(conditionName).equals("") && !curInfoPoint.get(conditionName).equals("unknown")) {
String info = curInfoPoint.get(conditionName);
String destination = info.split(":")[1];
String site = historyInfoPoint.get("site");
String newInfo = info.replace(destination, worldController.findLocationName(gameEnv, destination, site));
logWriter.record(conditionName + ": 将’" + info + "‘替换为‘" + newInfo + "'", 1);
curInfoPoint.put(conditionName, newInfo);
}
}
}
}
......@@ -12,20 +12,20 @@ import java.util.Map;
public class GlobalVariableConstructor extends ElementConstructor {
public GlobalVariableConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet<String> exceptRelation, StringBuffer POS) {
public GlobalVariableConstructor(SqlHelper helper, int botId, String botAccount, Map<String, StringBuffer> keywordMap, HashSet<String> exceptRelation, StringBuffer POS) {
super();
this.helper = helper;
this.botId = botId;
this.botAccount = botAccount;
this.exceptRelation = exceptRelation;
this.skipCount = skipCount;
this.keywordMap = keywordMap;
this.POS = POS;
}
public void construct(JSONObject gameElements, UserInfo userinfo) {
try {
String category, name, description, attrName, attrValue;
String category, name, description, attrValue;
JSONArray globalVariable = gameElements.getJSONArray("globalVariable");
Map<String, String> attribute = null;
Iterator<String> attrIter = null;
......@@ -33,9 +33,9 @@ public class GlobalVariableConstructor extends ElementConstructor {
for (JSONObject variableList : globalVariable.toJavaList(JSONObject.class)) {
category = (String) variableList.get("category");
attribute = gameElements.toJavaObject(variableList.getJSONObject("variables"), Map.class);
attrIter = attribute.keySet().iterator();
while (attrIter.hasNext()) {
attrName = attrIter.next();
for(String attrName:attribute.keySet()) {
attrValue = attribute.get(attrName);
varInitialMap.put("globalVariable_" + category + "_" + attrName, attrValue);
}
......@@ -54,6 +54,7 @@ public class GlobalVariableConstructor extends ElementConstructor {
}catch (Exception e){
operationStatus = 0;
message = "全局变量处理出现异常";
e.printStackTrace();
return;
}
}
......
......@@ -12,50 +12,63 @@ public class ItemConstructor extends ElementConstructor {
public ItemConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet<String> exceptRelation, StringBuffer POS) {
public ItemConstructor(SqlHelper helper, int botId, String botAccount, Map<String, StringBuffer> keywordMap, HashSet<String> exceptRelation, StringBuffer POS) {
super();
this.helper = helper;
this.botId = botId;
this.botAccount = botAccount;
this.exceptRelation = exceptRelation;
this.skipCount = skipCount;
this.keywordMap = keywordMap;
this.POS = POS;
}
public void construct(JSONObject gameElements, UserInfo userinfo) {
try {
String category, name, className, description, attrName, attrValue;
String pattern1 = keywordMap.get("item_location_pattern").toString();
String category, name, className, description, attrValue;
JSONArray goods = gameElements.getJSONArray("goods");
Map<String, String> attribute = null;
Iterator<String> attrIter = null;
HashSet<String> classSet = new HashSet<String>();
keywordMap.putIfAbsent("item_wenzainali", new StringBuffer());
keywordMap.putIfAbsent("item_shishenme", new StringBuffer());
keywordMap.putIfAbsent("item_know_exist_what", new StringBuffer());
keywordMap.putIfAbsent("item_nums", new StringBuffer());
//与物品属性查询相关的所有condition
ArrayList<String> attrRelateConditions = new ArrayList<String>() {
{
add("nums");
add("shishenme");
}
};
String attrRelateConditions[] = {"nums", "shishenme"};
//与物品类查询相关的所有condition
ArrayList<String> classRelateConditions = new ArrayList<String>() {
{
add("know_exist_what");
}
};
String classRelateConditions[] = {"know_exist_what" };
String locationRelateConditions[] = {"wenzainali"};
//如何找到×××××× ,这样的condition
String findRelateConditions[] = {"want_know_zenmezuo"};
String findPattern = keywordMap.get("find_pattern").toString();
StringBuffer keywords = new StringBuffer();
StringBuffer classKeywords = new StringBuffer();
for (JSONObject good : goods.toJavaList(JSONObject.class)) {
name = (String) good.get("name");
//添加词性
if(!name.equals(""))
POS.append("=" + name + "|名词\r\n");
className = (String) good.get("class");
if(!className.equals(""))
POS.append("=" + className + "|名词\r\n");
keywordMap.get("item_" + locationRelateConditions[0]).append(pattern1.replace("name", name));
//添加所有物品类别
if (!classSet.contains(className)) {
classSet.add(className);
//添加周围有什么士兵等关于类别的关键词
......@@ -63,34 +76,58 @@ public class ItemConstructor extends ElementConstructor {
}
attribute = gameElements.toJavaObject(good.getJSONObject("attr"), Map.class);
attrIter = attribute.keySet().iterator();
while (attrIter.hasNext()) {
attrName = attrIter.next();
for(String attrName: attribute.keySet()){
if(!attrName.equals(""))
POS.append("=" + attrName + "|名词\r\n");
attrValue = attribute.get(attrName);
keywords.append("+" + name + ":" + attrName);
for(String condition: attrRelateConditions){
keywordMap.get("item_" + condition).append("+" + name + ":" + attrName);
}
}
}
//与地点查询相关的condition
for(String conditionName: locationRelateConditions){
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString() + "," +
"zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ",
"match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}",
" ",
"goods_query:queryLocationByConditionName:" + conditionName
);
JConfig.activateCopy(jConfig, jConfigList, "item");
//jConfigList.add(jConfig);
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}",
" ",
"goods_query:queryLocationByConditionName:" + conditionName
);
JConfig.activateCopy(jConfig, jConfigList, "item");
}
//根据根据物品名字和属性查询属性值
for (String conditionName : attrRelateConditions) {
jConfig = new JConfig(
conditionName + "::match-Include=" + keywords, " ",
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}",
" ",
"goods_query:queryAttrByGoodsName:" + conditionName
);
jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig);
JConfig.activateCopy(jConfig, jConfigList, "item");
}
//根据类名和地点查询所有实例
//根据类名查询周围所有实例
for (String conditionName : attrRelateConditions) {
jConfig = new JConfig(
conditionName + "::match-Include=" + classKeywords, " ",
......@@ -99,8 +136,7 @@ public class ItemConstructor extends ElementConstructor {
" ",
"goods_query:queryAroundGoodsByClassName:" + conditionName
);
jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig);
JConfig.activateCopy(jConfig, jConfigList, "item");
}
} catch(Exception e){
operationStatus = 0;
......
......@@ -27,6 +27,7 @@ public class PlotConstructor extends ElementConstructor {
HashMap<String, Boolean> visited = new HashMap<String, Boolean>();
public static String TASK_LINE = "任务线_%s进度";
public static String TASK_CONDITION = "任务线%s最后一个condition";
public static String TASK_REPLY = "任务线%s最后的回答";
......@@ -35,13 +36,13 @@ public class PlotConstructor extends ElementConstructor {
return id2j;
}
public PlotConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet<String> exceptRelation, StringBuffer POS) {
public PlotConstructor(SqlHelper helper, int botId, String botAccount, Map<String, StringBuffer> keywordMap, HashSet<String> exceptRelation, StringBuffer POS) {
super();
this.helper = helper;
this.botId = botId;
this.botAccount = botAccount;
this.exceptRelation = exceptRelation;
this.skipCount = skipCount;
this.keywordMap = keywordMap;
this.POS = POS;
}
......@@ -256,7 +257,13 @@ public class PlotConstructor extends ElementConstructor {
lastTaskReply = "任务线" + nextLocation + "最后的回答";
//额外条件是任务线进度达到当前剧情,额外更新变量是将任务线移动至下一剧情
/**
* 额外条件是任务线进度达到当前剧情,额外更新变量是将任务线移动至下一剧情
* 如果某个地点的剧情已经到结尾啦,那么有两种解决方法:
* 1: 将剧情停留在最后一步剧情
* 2. 设一个专门的剧情表示剧情的结尾
*/
extraHP = taskLineName + "::match-Include=" + id + ",site::match-Include=" + location + "," + id + "::number-BiggerOrEqual=" + 1;
if(!id.equals(nextId)){
extraHP += "," + nextId + "::match-Include=null";
......@@ -342,7 +349,7 @@ public class PlotConstructor extends ElementConstructor {
//没有当前条件的限制,
if (curPremiseList.size() == 0){
jConfig.setFeature(jConfig.getFeature() + ",activate,post::gameQA(" + QA_URL + ")");
jConfig.setNextStep("queryskip*,map*");
jConfig.setNextStep("queryskip*,map*,item*,npc*");
jConfig.setUpdateKnowledge(jConfig.getUpdateKnowledge() + "-<-临时变量condition:"+ nextCondition +"-<-临时变量reply:var={reply-3}");
jConfig.setNextStepStatus("active");
}
......@@ -350,8 +357,6 @@ public class PlotConstructor extends ElementConstructor {
jConfigList.add(jConfig);
......
......@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import com.qiwu.chatbotbackend.entity.Condition;
import com.qiwu.chatbotbackend.entity.Solution;
import com.qiwu.chatbotbackend.entity.UserInfo;
import org.apache.http.message.BasicNameValuePair;
import java.io.UnsupportedEncodingException;
......@@ -89,8 +90,7 @@ public class FormsPoster {
}
}
}else {
if(URL.equals(QA_URL
))
if(URL.equals(QA_URL))
ans.setAnswer("qa_threshold, game_step, query_text 看看少了哪个");
else
ans.setAnswer("提交表单出现异常");
......@@ -170,7 +170,7 @@ public class FormsPoster {
* @param URL
* @throws UnsupportedEncodingException
*/
public void postGameQA(Map<String ,String> curInfoPoint, Map<String ,String> historyInfoPoint, Solution ans,GameEnv gameEnv, WorldController worldController, String URL) throws UnsupportedEncodingException {
public void postGameQA(Map<String ,String> curInfoPoint, Map<String ,String> historyInfoPoint, Solution ans,GameEnv gameEnv, WorldController worldController, String URL, UserInfo userInfo) throws UnsupportedEncodingException {
String key, keyName;
Iterator<String> k_iter = null;
List<BasicNameValuePair> pairList = new ArrayList<BasicNameValuePair>();
......@@ -206,7 +206,8 @@ public class FormsPoster {
Matcher m = findTalker.matcher(textscore.get(0));
if(m.find()) {
npc = m.group(1);
if (worldController.worldOperation(gameEnv, "NPC_query", "queryLocationByNPCName:" + npc, curInfoPoint, historyInfoPoint).equals(site)){
if (worldController.worldOperation(gameEnv, "npc_query", "queryLocationByNPCName:" + npc, curInfoPoint, historyInfoPoint).equals(
userInfo.varInitialMap.get("FIND_NPC_LOCATION").replace("[人名]", npc).replace("[地点]", historyInfoPoint.get("site")))){
historyInfoPoint.put("common_answer", textscore.get(0));
historyInfoPoint.put("qa_score", String.valueOf(textscore.get(1)));
break;
......
......@@ -191,5 +191,22 @@ public class MyFunc {
}
public static String randStr(String strList[]){
String reply;
int randNum = (int) (Math.random() * strList.length);
reply = strList[randNum];
return reply;
}
public static String randStr(List<String> strList){
String reply;
int randNum = (int) (Math.random() * strList.size());
reply = strList.get(randNum);
return reply;
}
}
\ No newline at end of file
......@@ -6,6 +6,8 @@ import com.qiwu.chatbotbackend.entity.Solution;
import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.gameDesign.PlotConstructor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -27,10 +29,9 @@ public class ResponseFilter {
String site = historyInfoPoint.get("site");
String answer[] = reply.split("~");
int randNum = (int) (Math.random() * answer.length);
reply = answer[randNum];
if(reply.startsWith("【" + historyInfoPoint.get(PlotConstructor.ASSISTANT))){
reply = MyFunc.randStr(reply.split("~"));
if(reply.startsWith("【" + historyInfoPoint.get(PlotConstructor.ASSISTANT)+ "】") ){
return reply;
}else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter)){
return reply;
......@@ -38,26 +39,43 @@ public class ResponseFilter {
}
if(userInfo.varInitialMap.get("unknownTextList") != null){
List<String> unknownList = new ArrayList<String>();
for(String ans:userInfo.varInitialMap.get("unknownTextList").split("~")){
if(ans.equals(""))
continue;
if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter)){
return ans;
unknownList.add(ans);
//return ans;
}
}
if(unknownList.size() > 0){
return MyFunc.randStr(unknownList);
}
}
if(userInfo.varInitialMap.get("finalUnknownText") != null){
finalUnknownText = userInfo.varInitialMap.get("finalUnknownText");
if (sameLocation(finalUnknownText, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter)){
return finalUnknownText;
List<String> finalUnknownList = new ArrayList<String>();
for(String ans:finalUnknownText.split("~")){
if(ans.equals(""))
continue;
if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter)){
finalUnknownList.add(ans);
//return ans;
}
}
if(finalUnknownList.size() > 0){
return MyFunc.randStr(finalUnknownList);
}
}
}
return "";
return "找不到匹配文本";
}
static Boolean sameLocation(String reply, Map<String ,String> curInfoPoint, Map<String ,String> historyInfoPoint, GameEnv gameEnv, WorldController worldController, String site, LogWriter logWriter){
......@@ -66,7 +84,7 @@ public class ResponseFilter {
Matcher m = findTalker.matcher(reply);
if(m.find()) {
npc = m.group(1);
if (worldController.worldOperation(gameEnv, "NPC_query", "queryLocationByNPCName:" + npc, curInfoPoint, historyInfoPoint).equals(site)){
if (worldController.worldOperation(gameEnv, "npc_query", "queryLocationByNPCName:" + npc, curInfoPoint, historyInfoPoint).equals(site)){
return true;
}{
logWriter.record(npc +"不在" + site + "跳过",1 );
......
......@@ -24,6 +24,7 @@ import java.util.*;
public class GameDesignServlet extends HttpServlet {
String POST_URL = "http://localhost:1111/conditionProcess";
String KEYWORD_DIR = "keywords.txt";
//分组及其相应的id,id初始化为0, 新建分组成功后id会更新。
HashMap<String, Integer> categoryMap = new HashMap<String, Integer>(){
{
......@@ -42,8 +43,11 @@ public class GameDesignServlet extends HttpServlet {
//所有需要修改的词性
StringBuffer POS = new StringBuffer();
//每个condition的三元组两端需要补充的关键词,比如npc名字、npc属性等
HashMap<String, HashSet<String>> relationKeywords = new HashMap<String, HashSet<String>>();
//每个condition的三元组两端需要补充的关键词,比如npc名字、npc属性等,格式为: "conditionName_tail/head":"keywords"
HashMap<String, HashSet<String>> additionalKeywords = new HashMap<String, HashSet<String>>();
//预先定义好的所有condition相关的关键词,格式为 "conditionName_标签":"keywords"
Map<String, StringBuffer> keywordMap = new HashMap<String, StringBuffer>();
//特定的relation的三元组不会被添加到relationKeywords
HashSet<String> exceptRelation = new HashSet<String>();
......@@ -105,35 +109,40 @@ public class GameDesignServlet extends HttpServlet {
StringBuffer mergedConfigText = new StringBuffer();
int skipCount = 0;
//从文件中读取condition相关的关键词
System.out.println("----------------------read-------------------------/r------------------------------------------------------");
readKeywords(keywordMap, KEYWORD_DIR);
String moduleList[] = {"map", "goods", "globalVariable", "npc", "plots"};
for(String moduleName: moduleList){
switch (moduleName) {
case "map":
moduleName2 = "地图";
constructor = new MapConstructor2(helper, botId, skipCount, botAccount, exceptRelation, POS);
constructor = new MapConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo);
break;
case "plots":
moduleName2 = "剧情";
constructor = new PlotConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS);
constructor = new PlotConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo);
root = ((PlotConstructor) constructor).getId2j().get((String) gameElements.get("start"));
break;
case "goods":
moduleName2 = "物品";
constructor = new ItemConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS);
constructor = new ItemConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo);
break;
case "globalVariable":
moduleName2 = "全局变量";
constructor = new GlobalVariableConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS);
constructor = new GlobalVariableConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo);
break;
case "npc":
moduleName2 = "NPC";
constructor = new CharacterConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS);
constructor = new CharacterConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo);
break;
default:
......@@ -150,7 +159,7 @@ public class GameDesignServlet extends HttpServlet {
List<JSONObject> jsonList = new ArrayList<JSONObject>();
for(JConfig jConfig: constructor.getjConfigList()){
json = jConfig.toJson(constructor.getConditionDescription());
constructor.parseKeyword(json, relationKeywords, exceptRelation);
constructor.parseKeyword(json, additionalKeywords, exceptRelation);
jsonList.add(json);
}
......@@ -174,7 +183,7 @@ public class GameDesignServlet extends HttpServlet {
UserInfoController.buildUserInfo(br, userinfo, true);
context.setAttribute(botAccount, userinfo);
ConditionTableController.writeConfigText(botAccount, userinfo);
String postResult = actionRegenerate(root, gameElements, userinfo, relationKeywords, exceptRelation, POS);
String postResult = actionRegenerate(root, gameElements, userinfo, additionalKeywords, exceptRelation, POS);
if(!postResult.equals("success")){
returnStatus = 0;
......@@ -229,7 +238,7 @@ public class GameDesignServlet extends HttpServlet {
return deleteConfigFlag && deleteVariableFlag;
}
public String actionRegenerate(JSONObject root, JSONObject gameElements, UserInfo userInfo, HashMap<String, HashSet<String>> relationKeywords, HashSet<String> exceptRelation, StringBuffer POS){
public String actionRegenerate(JSONObject root, JSONObject gameElements, UserInfo userInfo, HashMap<String, HashSet<String>> additionalKeywords, HashSet<String> exceptRelation, StringBuffer POS){
String startCondition, POS2 = "";
String botName = (String)gameElements.get("botName");
JSONObject returnMessage = null;
......@@ -243,7 +252,7 @@ public class GameDesignServlet extends HttpServlet {
actionPostData.put("botId", (Integer)gameElements.get("botId"));
actionPostData.put("type", "game_plot_init");
actionPostData.put("welcome", "欢迎来到" + (String)gameElements.get("botName") + ",请说开始剧情或者重新开始");
actionPostData.put("relationKeywords", relationKeywords);
actionPostData.put("relationKeywords", additionalKeywords);
actionPostData.put("auth", gameElements.get("auth"));
......@@ -271,4 +280,35 @@ public class GameDesignServlet extends HttpServlet {
}
}
public void readKeywords(Map<String, StringBuffer> keywordsMap, String path){
File file = new File(path);
String line, pair[];
System.out.println(file.getAbsolutePath());
if(file.exists()){
FileReader reader = null;
try {
reader = new FileReader(file);
BufferedReader br = new BufferedReader(reader);
while ((line = br.readLine()) != null) {
if(!line.equals("") && !line.startsWith("#")){
pair = line.split("\\|", 2);
keywordsMap.put(pair[0], new StringBuffer(pair[1]));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
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