Commit f0e522d1 by hxw

优化游戏生成效率

parent 955c5e93
...@@ -116,14 +116,15 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -116,14 +116,15 @@ public class CharacterConstructor extends ElementConstructor {
for (String conditionName : locationRelateConditions) { for (String conditionName : locationRelateConditions) {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ", conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName "match,return-0", "", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "npc"); JConfig.activateCopy(jConfig, jConfigList, "npc");
//zainali 和wenzainali 都识别到时优先匹配wenzainali
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName) + "," + conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName) + "," +
"zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ", "zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName "match,return-0", "", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "npc"); JConfig.activateCopy(jConfig, jConfigList, "npc");
//jConfigList.add(jConfig); //jConfigList.add(jConfig);
...@@ -133,7 +134,7 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -133,7 +134,7 @@ public class CharacterConstructor extends ElementConstructor {
for(String conditionName: attrRelateConditions){ for(String conditionName: attrRelateConditions){
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ", conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao", "match,return-0", "", "yaobuyao",
"npc_query:queryAttrByNPCName:" + conditionName "npc_query:queryAttrByNPCName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "npc"); JConfig.activateCopy(jConfig, jConfigList, "npc");
...@@ -144,7 +145,7 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -144,7 +145,7 @@ public class CharacterConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ", conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao", "match,return-0", "", "yaobuyao",
"npc_query:queryAroundNpcByClassName:" + conditionName "npc_query:queryAroundNpcByClassName:" + conditionName
); );
JConfig.activateCopy(jConfig, jConfigList, "npc"); JConfig.activateCopy(jConfig, jConfigList, "npc");
...@@ -156,7 +157,7 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -156,7 +157,7 @@ public class CharacterConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName).toString(), " ", conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName).toString(), " ",
"match,return-0", "match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{npc_query-2}", "",
" ", " ",
"npc_query:queryFindNPCWay:" + conditionName "npc_query:queryFindNPCWay:" + conditionName
); );
...@@ -168,7 +169,7 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -168,7 +169,7 @@ public class CharacterConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("talker_" + conditionName).toString().replace("botname", botName), " ", conditionName + "::match-Include=" + keywordMap.get("talker_" + conditionName).toString().replace("botname", botName), " ",
"match,return-0", "match,return-0",
"{npc_query-2}", "",
" ", " ",
"npc_query:queryLastTalker:" "npc_query:queryLastTalker:"
); );
......
...@@ -26,20 +26,18 @@ public class GlobalVariableConstructor extends ElementConstructor { ...@@ -26,20 +26,18 @@ public class GlobalVariableConstructor extends ElementConstructor {
try { try {
String category, name, description, attrValue; String category, name, description, attrValue;
JSONArray globalVariable = gameElements.getJSONArray("globalVariable"); JSONObject globalVariable = gameElements.getJSONObject("globalVariable");
Map<String, String> attribute = null; Map<String, String> attribute = null;
Iterator<String> attrIter = null; Iterator<String> attrIter = null;
for (JSONObject variableList : globalVariable.toJavaList(JSONObject.class)) {
category = (String) variableList.get("category");
attribute = gameElements.toJavaObject(variableList.getJSONObject("variables"), Map.class);
for(String attrName:attribute.keySet()) {
attrValue = attribute.get(attrName); for(String attrName:globalVariable.keySet()) {
attrValue = (String)globalVariable.get(attrName);
varInitialMap.put("globalVariable_" + attrName, attrValue); varInitialMap.put("globalVariable_" + attrName, attrValue);
} }
}
varInitialMap.put("botType", "game"); varInitialMap.put("botType", "game");
varInitialMap.put("unknownTextList", (String)gameElements.get("unknownTextList")); varInitialMap.put("unknownTextList", (String)gameElements.get("unknownTextList"));
......
...@@ -113,7 +113,7 @@ public class ItemConstructor extends ElementConstructor { ...@@ -113,7 +113,7 @@ public class ItemConstructor extends ElementConstructor {
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString() + "," + conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString() + "," +
"zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ", "zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ",
"match,return-0", "match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", "",
" ", " ",
"goods_query:queryLocationByConditionName:" + conditionName "goods_query:queryLocationByConditionName:" + conditionName
); );
...@@ -121,7 +121,7 @@ public class ItemConstructor extends ElementConstructor { ...@@ -121,7 +121,7 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ", conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0", "match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", "",
" ", " ",
"goods_query:queryLocationByConditionName:" + conditionName "goods_query:queryLocationByConditionName:" + conditionName
); );
...@@ -134,7 +134,7 @@ public class ItemConstructor extends ElementConstructor { ...@@ -134,7 +134,7 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ", conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0", "match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", "",
" ", " ",
"goods_query:queryAttrByGoodsName:" + conditionName "goods_query:queryAttrByGoodsName:" + conditionName
); );
...@@ -147,7 +147,7 @@ public class ItemConstructor extends ElementConstructor { ...@@ -147,7 +147,7 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + classKeywords, " ", conditionName + "::match-Include=" + classKeywords, " ",
"match,return-0", "match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", "",
" ", " ",
"goods_query:queryAroundGoodsByClassName:" + conditionName "goods_query:queryAroundGoodsByClassName:" + conditionName
); );
...@@ -159,7 +159,7 @@ public class ItemConstructor extends ElementConstructor { ...@@ -159,7 +159,7 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ", conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0", "match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", "",
" ", " ",
"goods_query:queryPlayerItems:" + conditionName "goods_query:queryPlayerItems:" + conditionName
); );
...@@ -171,7 +171,7 @@ public class ItemConstructor extends ElementConstructor { ...@@ -171,7 +171,7 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ", conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0", "match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", "",
" ", " ",
"goods_query:queryFindItemWay:" + conditionName "goods_query:queryFindItemWay:" + conditionName
); );
......
...@@ -18,7 +18,7 @@ public class FormsPoster { ...@@ -18,7 +18,7 @@ public class FormsPoster {
LogWriter logWriter = null; LogWriter logWriter = null;
public static String QA_URL = "http://qcloud-gz1.chewrobot.com:58000/game"; public static String QA_URL = "http://aliyun-hz1.chewrobot.com:58000/game";
public FormsPoster(LogWriter logWriter) { public FormsPoster(LogWriter logWriter) {
this.logWriter = logWriter; this.logWriter = logWriter;
...@@ -33,7 +33,7 @@ public class FormsPoster { ...@@ -33,7 +33,7 @@ public class FormsPoster {
} }
}; };
static String TALKER = "^【(.*?)】"; static String TALKER = "【(.*?)@.*?】";
/** /**
* 提交类型为all时,会把当前信息点和历史信息点都作为post到另一个服务器 * 提交类型为all时,会把当前信息点和历史信息点都作为post到另一个服务器
...@@ -51,7 +51,7 @@ public class FormsPoster { ...@@ -51,7 +51,7 @@ public class FormsPoster {
k_iter = curInfoPoint.keySet().iterator(); k_iter = curInfoPoint.keySet().iterator();
while (k_iter.hasNext()) { while (k_iter.hasNext()) {
key = k_iter.next(); key = k_iter.next();
if (curInfoPoint.get(key) != "") if (curInfoPoint.get(key) != null && !curInfoPoint.get(key).equals(""))
//infoMap.put(key + "_cur", curInfoPoint.get(key)[0]); //infoMap.put(key + "_cur", curInfoPoint.get(key)[0]);
pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key))); pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key)));
} }
...@@ -59,14 +59,17 @@ public class FormsPoster { ...@@ -59,14 +59,17 @@ public class FormsPoster {
k_iter = historyInfoPoint.keySet().iterator(); k_iter = historyInfoPoint.keySet().iterator();
while (k_iter.hasNext()) { while (k_iter.hasNext()) {
key = k_iter.next(); key = k_iter.next();
if (historyInfoPoint.get(key) != "")
//infoMap.put(key + "_his", historyInfoPoint.get(key)); if(historyInfoPoint.get(key) != null && !historyInfoPoint.get(key).equals("")) {
if (key.equals("game_step") || key.equals("qa_threshold")) if (skipSet.contains(key))
continue;
if (curInfoPoint.get(key) == null || curInfoPoint.equals("")) {
pairList.add(new BasicNameValuePair(key, historyInfoPoint.get(key))); pairList.add(new BasicNameValuePair(key, historyInfoPoint.get(key)));
else if(skipSet.contains(key)){} } else {
else
pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key))); pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key)));
} }
}
}
logWriter.record("提交表单的数据:<br>" + pairList.toString(), 2); logWriter.record("提交表单的数据:<br>" + pairList.toString(), 2);
...@@ -121,16 +124,20 @@ public class FormsPoster { ...@@ -121,16 +124,20 @@ public class FormsPoster {
k_iter = ansCondition.currentPremise.keySet().iterator(); k_iter = ansCondition.currentPremise.keySet().iterator();
while (k_iter.hasNext()) { while (k_iter.hasNext()) {
key = k_iter.next().split("::")[0]; key = k_iter.next().split("::")[0];
if (curInfoPoint.get(key) != "") if (curInfoPoint.get(key) != null && !curInfoPoint.equals(""))
pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key))); pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key)));
} }
k_iter = ansCondition.historyPremise.keySet().iterator(); k_iter = ansCondition.historyPremise.keySet().iterator();
while (k_iter.hasNext()) { while (k_iter.hasNext()) {
key = k_iter.next().split("::")[0]; key = k_iter.next().split("::")[0];
if (historyInfoPoint.get(key) != "") if(!historyInfoPoint.get(key).equals("")) {
if (curInfoPoint.get(key) == null || curInfoPoint.equals("")) {
pairList.add(new BasicNameValuePair(key, historyInfoPoint.get(key)));
} else {
pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key))); pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key)));
//infoMap.put(key + "_his", historyInfoPoint.get(key)); }
}
} }
logWriter.record("提交表单的数据:<br>" + pairList.toString(), 2); logWriter.record("提交表单的数据:<br>" + pairList.toString(), 2);
...@@ -193,6 +200,7 @@ public class FormsPoster { ...@@ -193,6 +200,7 @@ public class FormsPoster {
System.out.println(jobj.toJSONString()); System.out.println(jobj.toJSONString());
if((Integer)jobj.get("post_status") == 1){ if((Integer)jobj.get("post_status") == 1){
if(jobj.getJSONArray("qa_candidates") != null && jobj.get("qa_status").equals("OK")){ if(jobj.getJSONArray("qa_candidates") != null && jobj.get("qa_status").equals("OK")){
//设置初始值
historyInfoPoint.put("common_answer", ""); historyInfoPoint.put("common_answer", "");
historyInfoPoint.put("qa_score", "0"); historyInfoPoint.put("qa_score", "0");
historyInfoPoint.put("qa_status", "OK"); historyInfoPoint.put("qa_status", "OK");
......
...@@ -184,6 +184,7 @@ public class MyFunc { ...@@ -184,6 +184,7 @@ public class MyFunc {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
jobj.put("post_status", 0);
} }
......
package com.qiwu.chatbotbackend.processing; package com.qiwu.chatbotbackend.processing;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv; import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import com.qiwu.chatbotbackend.entity.Solution; import com.qiwu.chatbotbackend.entity.Solution;
import com.qiwu.chatbotbackend.entity.Condition; import com.qiwu.chatbotbackend.entity.Condition;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.gameDesign.GameUtil;
import com.qiwu.chatbotbackend.task.utils.BasicBotUtil; import com.qiwu.chatbotbackend.task.utils.BasicBotUtil;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import java.io.*; import java.io.*;
...@@ -58,6 +49,11 @@ public class QuestionMatcher { ...@@ -58,6 +49,11 @@ public class QuestionMatcher {
} }
public QuestionMatcher(){
}
/** /**
...@@ -93,15 +89,19 @@ public class QuestionMatcher { ...@@ -93,15 +89,19 @@ public class QuestionMatcher {
for (Condition condition : conditionList) { for (Condition condition : conditionList) {
if (condition.status.equals("waiting")){ if (condition.status.equals("waiting")){
if ((condition.auxiliaryPriority > bestMatch.auxiliaryPriority) || (condition.auxiliaryPriority == bestMatch.auxiliaryPriority && condition.priority > bestMatch.priority)){ if ((condition.auxiliaryPriority > bestMatch.auxiliaryPriority) || (condition.auxiliaryPriority == bestMatch.auxiliaryPriority && condition.priority > bestMatch.priority)
|| condition.featureMap.get("activate") != null){
if(conditionSatisfy(condition)){ if(conditionSatisfy(condition)){
if (condition.featureMap.get("activate") != null && !condition.featureMap.containsKey("post")) { if (condition.featureMap.get("activate") != null && !condition.featureMap.containsKey("post")) {
//有post这个feature的配置条目会在最后激活它的待激活列表,这里就不激活了。 //有post这个feature的配置条目会在最后激活它的待激活列表,这里就不激活了。
activateCondition(activatedQueue, curInfoPoint.get("bot_name"), condition.priority, condition.auxiliaryPriority, condition.nextStep, context); activateCondition(activatedQueue, curInfoPoint.get("bot_name"), condition.priority, condition.auxiliaryPriority, condition.nextStep, context);
} }
if((condition.auxiliaryPriority > bestMatch.auxiliaryPriority) || (condition.auxiliaryPriority == bestMatch.auxiliaryPriority && condition.priority > bestMatch.priority)) {
bestMatch = condition; bestMatch = condition;
logWriter.record("匹配更新为:\"" + userinfo.id2config.get(condition.id) + "\"", 2); logWriter.record("匹配更新为:\"" + userinfo.id2config.get(condition.id) + "\"", 2);
logWriter.writeln(); logWriter.writeln();
}
} }
...@@ -139,6 +139,7 @@ public class QuestionMatcher { ...@@ -139,6 +139,7 @@ public class QuestionMatcher {
if ((condition.auxiliaryPriority > bestMatch.auxiliaryPriority) || (condition.auxiliaryPriority == bestMatch.auxiliaryPriority && condition.activePriority > bestMatch.activePriority) if ((condition.auxiliaryPriority > bestMatch.auxiliaryPriority) || (condition.auxiliaryPriority == bestMatch.auxiliaryPriority && condition.activePriority > bestMatch.activePriority)
|| condition.featureMap.get("activate") != null
|| bestMatch.nextStep.contains(String.valueOf(condition.id)) || (!condition.configName.equals("") && bestMatch.nextStep.contains(condition.configName.substring(0,3)))){ || bestMatch.nextStep.contains(String.valueOf(condition.id)) || (!condition.configName.equals("") && bestMatch.nextStep.contains(condition.configName.substring(0,3)))){
//激活优先级先比较,但是如果激活的是无条件的就直接判断名字。 //激活优先级先比较,但是如果激活的是无条件的就直接判断名字。
if(conditionSatisfy(condition)){ if(conditionSatisfy(condition)){
...@@ -146,9 +147,12 @@ public class QuestionMatcher { ...@@ -146,9 +147,12 @@ public class QuestionMatcher {
activateCondition(activatedQueue, curInfoPoint.get("bot_name"), condition.priority, condition.auxiliaryPriority, condition.nextStep, context); activateCondition(activatedQueue, curInfoPoint.get("bot_name"), condition.priority, condition.auxiliaryPriority, condition.nextStep, context);
} }
if((condition.auxiliaryPriority > bestMatch.auxiliaryPriority) || (condition.auxiliaryPriority == bestMatch.auxiliaryPriority && condition.activePriority > bestMatch.activePriority)) {
bestMatch = condition; bestMatch = condition;
logWriter.record("匹配更新为:\"" + userinfo.id2config.get(condition.id) + "\"", 2); logWriter.record("匹配更新为:\"" + userinfo.id2config.get(condition.id) + "\"", 2);
logWriter.writeln(); logWriter.writeln();
}
} }
...@@ -259,7 +263,7 @@ public class QuestionMatcher { ...@@ -259,7 +263,7 @@ public class QuestionMatcher {
String operator = ""; String operator = "";
try { try {
String splitPair[] = cmpType.split("-"); String splitPair[] = cmpType.split("-", 2);
if (splitPair.length > 1) { if (splitPair.length > 1) {
operator = splitPair[1]; operator = splitPair[1];
cmpType = splitPair[0]; cmpType = splitPair[0];
...@@ -279,10 +283,25 @@ public class QuestionMatcher { ...@@ -279,10 +283,25 @@ public class QuestionMatcher {
} }
} }
} else if(operator.equals("Exclude")) { } else if(operator.equals("Exclude")) {
if(keyword.contains(":")){
String ks[] = keyword.split(":", 2);
if(keywordSet.contains(ks[0]) || keywordSet.contains(ks[1]))
flag = false;
}else {
if (keywordSet.contains(keyword)) { if (keywordSet.contains(keyword)) {
flag = false; flag = false;
} }
}else { }
}else if(operator.equals("Have")){
for(String key:keywordSet){
if(key.equals(""))
continue;
if(!keyword.contains(key)){
flag = false;
break;
}
}
}else{
flag = false; flag = false;
} }
...@@ -474,81 +493,6 @@ public class QuestionMatcher { ...@@ -474,81 +493,6 @@ public class QuestionMatcher {
}
//--------------------------------------------------------------------
//为兼容旧数据
else if (cmpType.equals("numberBigger") && StringUtils.isNumeric(keyword)) {
int candidateA = 0;
int candidateB = 0;
candidateA = Integer.parseInt(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = Integer.parseInt(k);
break;
}
}
flag = candidateA > candidateB;
} else if (cmpType.equals("numberBiggerOrEqual") && StringUtils.isNumeric(keyword)) {
int candidateA = 0;
int candidateB = 0;
candidateA = Integer.parseInt(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = Integer.parseInt(k);
break;
}
}
flag = candidateA >= candidateB;
} else if (cmpType.equals("numberSmaller") && StringUtils.isNumeric(keyword)) {
int candidateA = 0;
int candidateB = 0;
candidateA = Integer.parseInt(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = Integer.parseInt(k);
break;
}
}
flag = candidateA < candidateB;
} else if (cmpType.equals("numberSmallerOrEqual") && StringUtils.isNumeric(keyword)) {
int candidateA = 0;
int candidateB = 0;
candidateA = Integer.parseInt(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = Integer.parseInt(k);
break;
}
}
flag = candidateA <= candidateB;
} else if (cmpType.equals("timeEarly")) {
long candidateA, candidateB = 0;
candidateA = MyFunc.transferToMillisecond(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = MyFunc.transferToMillisecond(k);
break;
}
}
flag = candidateA < candidateB;
} else if (cmpType.equals("timeLater")) {
long candidateA, candidateB = 0;
candidateA = MyFunc.transferToMillisecond(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = MyFunc.transferToMillisecond(k);
break;
}
}
flag = candidateA > candidateB;
} else if (cmpType.equals("any")) { } else if (cmpType.equals("any")) {
if (keyword.equals("")) //当前信息点中的关键词不为空即满足条件,为空则不满足 if (keyword.equals("")) //当前信息点中的关键词不为空即满足条件,为空则不满足
flag = false; flag = false;
......
...@@ -38,36 +38,75 @@ public class ResponseFilter { ...@@ -38,36 +38,75 @@ public class ResponseFilter {
return reply; return reply;
} }
if(reply.startsWith("【" + historyInfoPoint.get(PlotConstructor.ASSISTANT)+ "】") ){ if(reply.startsWith("【" + historyInfoPoint.get(PlotConstructor.ASSISTANT) + "@" + PlotConstructor.ASSISTANT_EMOTION + "】") ){
return reply; return reply;
}else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1){ }else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1){
return reply; return reply;
}else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0 && !reply.equals("")){ }else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0 && !reply.equals("")){
return appendTalker(reply,curInfoPoint, historyInfoPoint, gameEnv, worldController); return appendTalker(reply,curInfoPoint, historyInfoPoint, gameEnv, worldController);
}else if (reply.equals("") && !historyInfoPoint.get("common_answer").equals("")){ }else if (reply.equals("") && (
(historyInfoPoint.get("common_answer") != null && !historyInfoPoint.get("common_answer").equals("")))
|| (historyInfoPoint.get("map_query") != null && !historyInfoPoint.get("map_query").equals(""))
|| (historyInfoPoint.get("goods_query") != null && !historyInfoPoint.get("goods_query").equals("") )
|| (historyInfoPoint.get("npc_query") != null && !historyInfoPoint.get("npc_query").equals(""))
){
return reply; return reply;
} }
if(userInfo.varInitialMap.get("unknownTextList") != null){ if(userInfo.varInitialMap.get("unknownTextList") != null){
List<String> unknownList = new ArrayList<String>(); List<String> unknownList = new ArrayList<String>();
for(String ans:userInfo.varInitialMap.get("unknownTextList").split("~")){
if(ans.equals("")) String lastTalker = "";
//如果作者当前地点和剧情所在地点相同,那么回答unknown文本的人必须是剧情中的人
if(historyInfoPoint.get("game_step").endsWith(historyInfoPoint.get(String.format(PlotConstructor.TASK_LINE, site)))){
Matcher m = findTalker(historyInfoPoint.get(String.format(PlotConstructor.TASK_REPLY, site)));
while(m.find()) {
lastTalker = m.group(1);
}
for (String ans : userInfo.varInitialMap.get("unknownTextList").split("~")) {
if (ans.equals(""))
continue; continue;
if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1){ if (ans.contains(lastTalker) &&sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1) {
unknownList.add(ans); unknownList.add(ans);
//return ans; //return ans;
}else if(sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0){ } else if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0) {
unknownList.add(appendTalker(ans,curInfoPoint, historyInfoPoint, gameEnv, worldController)); unknownList.add(appendTalker(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController));
} }
} }
if(unknownList.size() > 0){ if (unknownList.size() > 0) {
return MyFunc.randStr(unknownList);
}
}else {
for (String ans : userInfo.varInitialMap.get("unknownTextList").split("~")) {
if (ans.equals(""))
continue;
if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1) {
unknownList.add(ans);
//return ans;
} else if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0) {
unknownList.add(appendTalker(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController));
}
}
if (unknownList.size() > 0) {
return MyFunc.randStr(unknownList); return MyFunc.randStr(unknownList);
} }
} }
}
if(userInfo.varInitialMap.get("finalUnknownText") != null){ if(userInfo.varInitialMap.get("finalUnknownText") != null){
finalUnknownText = userInfo.varInitialMap.get("finalUnknownText"); finalUnknownText = userInfo.varInitialMap.get("finalUnknownText");
List<String> finalUnknownList = new ArrayList<String>(); List<String> finalUnknownList = new ArrayList<String>();
for(String ans:finalUnknownText.split("~")){ for(String ans:finalUnknownText.split("~")){
if(ans.equals("")) if(ans.equals(""))
continue; continue;
...@@ -121,8 +160,14 @@ public class ResponseFilter { ...@@ -121,8 +160,14 @@ public class ResponseFilter {
npc = m.group(1); npc = m.group(1);
location = worldController.worldOperation(gameEnv, "npc_query", "queryLocationByNPCName:" + npc, curInfoPoint, historyInfoPoint); location = worldController.worldOperation(gameEnv, "npc_query", "queryLocationByNPCName:" + npc, curInfoPoint, historyInfoPoint);
if (location.equals(site) || location.equals("无处不在") || location.equals("任意地点")){ if (location.equals(site) || location.equals("无处不在") || location.equals("任意地点")){
logWriter.record("\"" + reply + "\":匹配", 1); if(gameEnv.queryNpcAttrByNpcName(npc, "能否说话").equals("能")){
flag = 1; flag = 1;
logWriter.record("\"" + reply + "\":匹配", 1);
}else {
flag = 2;
logWriter.record(npc + "不能说话", 1);
}
}else { }else {
logWriter.record("\"" + reply + "\":" + npc +"不在" + site + ",跳过",1 ); logWriter.record("\"" + reply + "\":" + npc +"不在" + site + ",跳过",1 );
flag = 2; flag = 2;
...@@ -144,7 +189,7 @@ public class ResponseFilter { ...@@ -144,7 +189,7 @@ public class ResponseFilter {
else else
npc = historyInfoPoint.get(PlotConstructor.ASSISTANT); npc = historyInfoPoint.get(PlotConstructor.ASSISTANT);
return "【" + npc + "】" + reply; return "【" + npc + "@0】" + reply;
} }
......
...@@ -414,6 +414,15 @@ public class WorldController { ...@@ -414,6 +414,15 @@ public class WorldController {
returnStr = format.replace("[任务描述]", userInfo.varInitialMap.get(PlotConstructor.TASK_DESCRIPTION)); returnStr = format.replace("[任务描述]", userInfo.varInitialMap.get(PlotConstructor.TASK_DESCRIPTION));
break; break;
case "queryWhereIam":
returnStr = userInfo.varInitialMap.get("WHERE_I_AM").replace("[地点名]", historyInfoPoint.get("site"));
break;
case "queryPathAt":
returnStr = userInfo.varInitialMap.get("PATH_AT").replace("[地点名]", historyInfoPoint.get("site"));
break;
case "queryPathAdjoin":
returnStr = userInfo.varInitialMap.get("PATH_ADJOINT");
break;
} }
} }
...@@ -432,7 +441,11 @@ public class WorldController { ...@@ -432,7 +441,11 @@ public class WorldController {
}else{ //增删改统一使用 }else{ //增删改统一使用
logWriter.record("更新环境--varName:" + varName + "valuePair:" + valuePair[0] + ":" + valuePair[1], 1); logWriter.record("更新环境--varName:" + varName + "valuePair:" + valuePair[0] + ":" + valuePair[1], 1);
try {
gameEnv.CUD(varName, valuePair[0], valuePair[1]); gameEnv.CUD(varName, valuePair[0], valuePair[1]);
} catch (Exception e){
System.out.println("更新环境出现异常--varName:" + varName + "valuePair:" + valuePair[0] + ":" + valuePair[1]);
}
} }
......
...@@ -17,6 +17,8 @@ import javax.servlet.http.HttpServletRequest; ...@@ -17,6 +17,8 @@ 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.format.DateTimeFormatter;
import java.util.*; import java.util.*;
...@@ -40,6 +42,12 @@ public class GameDesignServlet extends HttpServlet { ...@@ -40,6 +42,12 @@ public class GameDesignServlet extends HttpServlet {
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");
StringBuffer timeUsedDetect = new StringBuffer();
LocalDateTime ldt = LocalDateTime.now();
String now = ldt.format(dtf);
timeUsedDetect.append("接收请求的时间:").append(now);
//所有需要修改的词性 //所有需要修改的词性
StringBuffer POS = new StringBuffer(); StringBuffer POS = new StringBuffer();
...@@ -115,13 +123,17 @@ public class GameDesignServlet extends HttpServlet { ...@@ -115,13 +123,17 @@ public class GameDesignServlet extends HttpServlet {
System.out.println("----------------------read-------------------------/r------------------------------------------------------"); System.out.println("----------------------read-------------------------/r------------------------------------------------------");
readKeywords(keywordMap, KEYWORD_DIR); readKeywords(keywordMap, KEYWORD_DIR);
ldt = LocalDateTime.now();
now = ldt.format(dtf);
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 MapConstructor2(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
case "plots": case "plots":
...@@ -176,17 +188,31 @@ public class GameDesignServlet extends HttpServlet { ...@@ -176,17 +188,31 @@ public class GameDesignServlet extends HttpServlet {
break; break;
} }
ldt = LocalDateTime.now();
now = ldt.format(dtf);
timeUsedDetect.append("\n,").append(moduleName2).append("模块:").append(now);
} }
if(returnStatus == 1) { if(returnStatus == 1) {
ldt = LocalDateTime.now();
now = ldt.format(dtf);
timeUsedDetect.append("\n发送post请求预处理:").append(now);
StringReader sr = new StringReader(mergedConfigText.toString()); StringReader sr = new StringReader(mergedConfigText.toString());
BufferedReader br = new BufferedReader(sr); BufferedReader br = new BufferedReader(sr);
//System.out.println(mergedConfigText.toString()); //System.out.println(mergedConfigText.toString());
UserInfoController.buildUserInfo(br, userinfo, true); UserInfoController.buildUserInfo(br, userinfo, true);
context.setAttribute(botAccount, userinfo); context.setAttribute(botAccount, userinfo);
ConditionTableController.writeConfigText(botAccount, userinfo); ConditionTableController.writeConfigText(botAccount, userinfo);
ldt = LocalDateTime.now();
now = ldt.format(dtf);
timeUsedDetect.append("\n发送post请求前:").append(now);
String postResult = actionRegenerate(root, gameElements, userinfo, additionalKeywords, exceptRelation, POS); String postResult = actionRegenerate(root, gameElements, userinfo, additionalKeywords, exceptRelation, POS);
ldt = LocalDateTime.now();
now = ldt.format(dtf);
timeUsedDetect.append("\n发送post请求后:").append(now);
if(!postResult.equals("success")){ if(!postResult.equals("success")){
returnStatus = 0; returnStatus = 0;
returnMessage = postResult; returnMessage = postResult;
...@@ -204,12 +230,18 @@ public class GameDesignServlet extends HttpServlet { ...@@ -204,12 +230,18 @@ public class GameDesignServlet extends HttpServlet {
} }
System.out.println(timeUsedDetect.toString());
JSONObject responseJSONObject = new JSONObject(); JSONObject responseJSONObject = new JSONObject();
responseJSONObject.put("status", returnStatus); responseJSONObject.put("status", returnStatus);
responseJSONObject.put("message", returnMessage); responseJSONObject.put("message", returnMessage);
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8"); response.setContentType("application/json; charset=utf-8");
System.out.println("xx:" + responseJSONObject.toJSONString()); System.out.println("xx:" + responseJSONObject.toJSONString());
......
...@@ -25,8 +25,8 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -25,8 +25,8 @@ public class GetAnswerServlet extends HttpServlet {
*/ */
String NAME_MISSING_ERROR = "没找到bot名?"; String NAME_MISSING_ERROR = "没找到bot名?";
//String LOG_PATH = "/var/www/html/logs/"; String LOG_PATH = "/var/www/html/logs/";
String LOG_PATH = "/home/hxw/source/logs/"; //String LOG_PATH = "/home/hxw/source/logs/";
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8");
......
package com.qiwu.chatbotbackend.task.utils; package com.qiwu.chatbotbackend.task.utils;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
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.gameDesign.GameUtil;
import com.qiwu.chatbotbackend.processing.LogWriter; import com.qiwu.chatbotbackend.processing.LogWriter;
import com.qiwu.chatbotbackend.processing.WorldController;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import java.io.IOException; import java.io.IOException;
......
...@@ -3,12 +3,14 @@ package com.qiwu.chatbotbackend.task.utils; ...@@ -3,12 +3,14 @@ package com.qiwu.chatbotbackend.task.utils;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv; import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
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.gameDesign.PlotConstructor;
import com.qiwu.chatbotbackend.processing.ChatCacheController; import com.qiwu.chatbotbackend.processing.ChatCacheController;
import com.qiwu.chatbotbackend.processing.LogWriter; import com.qiwu.chatbotbackend.processing.LogWriter;
import com.qiwu.chatbotbackend.processing.WorldController; import com.qiwu.chatbotbackend.processing.WorldController;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map; import java.util.Map;
public class GameBotUtil extends BasicBotUtil{ public class GameBotUtil extends BasicBotUtil{
...@@ -47,6 +49,8 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -47,6 +49,8 @@ public class GameBotUtil extends BasicBotUtil{
} }
} }
historyInfoPoint.put("current_plot_site", historyInfoPoint.get("site"));
String activeList[] = historyInfoPoint.get("activeList").split("\\|"); String activeList[] = historyInfoPoint.get("activeList").split("\\|");
if(activeList.length == 0){ if(activeList.length == 0){
historyInfoPoint.put("临时变量condition", "yaobuyao"); historyInfoPoint.put("临时变量condition", "yaobuyao");
...@@ -67,17 +71,22 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -67,17 +71,22 @@ public class GameBotUtil extends BasicBotUtil{
e.printStackTrace(); e.printStackTrace();
} }
} }
String plot_jump_text = historyInfoPoint.get("plot_jump_text");
if(plot_jump_text != null && !plot_jump_text.equals("")) {
bestMatch.setAnswer(bestMatch.getAnswer() + plot_jump_text + " " );
historyInfoPoint.put("plot_jump_text", "");
}
String common_answer = historyInfoPoint.get("common_answer"); String queryList[] = { "plot_jump_text" ,"common_answer","map_query", "goods_query", "npc_query"};
if(common_answer != null && !common_answer.equals("") && !common_answer.equals("no answer")){ String queryResult;
bestMatch.setAnswer(common_answer + " " + bestMatch.getAnswer()); for(String queryName:queryList){
historyInfoPoint.put("common_answer", ""); queryResult = historyInfoPoint.get(queryName);
if(queryResult != null && !queryResult.equals("")){
if(queryName.equals("common_answer") && queryResult.equals("no answer"))
continue;
if(queryName.equals("map_query") || queryName.equals("goods_query") || queryName.equals("npc_query")){
queryResult = "【" + historyInfoPoint.get(PlotConstructor.ASSISTANT) + "@" + PlotConstructor.ASSISTANT_EMOTION + "】" + queryResult;
}
bestMatch.setAnswer(queryResult + bestMatch.getAnswer() + " " );
historyInfoPoint.put(queryName, "");
} }
}
...@@ -93,12 +102,26 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -93,12 +102,26 @@ public class GameBotUtil extends BasicBotUtil{
if(actionName.startsWith("npc_")){ if(actionName.startsWith("npc_")){
if(nameSeries.length == 4){ if(nameSeries.length == 4){
keyword = gameEnv.queryNpcAttrByNpcName(nameSeries[2], nameSeries[3]); keyword = gameEnv.queryNpcAttrByNpcName(nameSeries[2], nameSeries[3]);
}else if (nameSeries.length == 3){
if(nameSeries[1].equals("玩家") && nameSeries[2].equals("物品栏")) {
StringBuffer sb = new StringBuffer();
List<String> goods = gameEnv.queryGoodsByNpcName("玩家");
for (String good : goods) {
sb.append("+").append(good);
}
keyword = sb.toString();
}else{
keyword = gameEnv.queryNpcAttrByNpcName(nameSeries[1], nameSeries[2]);
}
} }
}else if (actionName.startsWith("goods_")) { }else if (actionName.startsWith("goods_")) {
if (nameSeries.length == 4) { if (nameSeries.length == 4) {
keyword = gameEnv.queryGoodsAttrByGoodsName(nameSeries[2], nameSeries[3]); keyword = gameEnv.queryGoodsAttrByGoodsName(nameSeries[2], nameSeries[3]);
System.out.println("return" + keyword); System.out.println("return" + keyword);
}else if (nameSeries.length == 3){
keyword = gameEnv.queryNpcAttrByNpcName(nameSeries[1], nameSeries[2]);
} }
}else if(actionName.startsWith("isNeighbour")){ }else if(actionName.startsWith("isNeighbour")){
String opPair[] = actionName.split(":"); String opPair[] = actionName.split(":");
...@@ -130,19 +153,22 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -130,19 +153,22 @@ public class GameBotUtil extends BasicBotUtil{
@Override @Override
public void putKeyword(String variableName, String updateValue){ public void putKeyword(String variableName, String updateValue){
String namePair[] = variableName.split("_");
//如果变量名开头为NPC或者item,就专门交给world处理 //如果变量名开头为NPC或者item,就专门交给world处理
if((variableName.startsWith("npc_") || variableName.startsWith("goods_") || variableName.startsWith("map_") || variableName.startsWith("place_"))){ if ((namePair[0].equals("npc") || namePair[0].equals("goods") || namePair[0].equals("map") || namePair[0].equals("place"))) {
try { try {
if(!updateValue.startsWith("query") && !updateValue.startsWith("update")){ if (!updateValue.startsWith("query") && !updateValue.startsWith("update")) {
updateValue = "update:" + updateValue; updateValue = "update:" + updateValue;
} }
String returnStr = worldController.worldOperation(gameEnv, variableName, updateValue, curInfoPoint, historyInfoPoint); String returnStr = worldController.worldOperation(gameEnv, variableName, updateValue, curInfoPoint, historyInfoPoint);
updateValue = returnStr; updateValue = returnStr;
}catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
updateValue = "游戏模块处理出错"; updateValue = "游戏模块处理出错";
} }
} }
historyInfoPoint.put(variableName, updateValue); historyInfoPoint.put(variableName, updateValue);
} }
......
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