Commit 8d68a55a by hxw

修复生成action的bug

parent 1d6c0138
......@@ -179,3 +179,12 @@ sql_connection_error=数据库连接获取失败
# -------------------------备份--------------------------------------
backup_error=备份失败
# --------------------------话术----------------------------------------
script_npc_intro=[人名]:[属性值]
script_item_intro=[物品名]:[属性值]
script_npc_in_place=[地点名]上有[人物列表]
script_item_in_place=[地点名]上有[物品列表]
script_all_in_place=[地点名]上有[人物物品列表]
......@@ -23,15 +23,16 @@ WHERE_CAN_I_GO|choose_gowhere_33|+qiwu:哪+qiwu:哪儿+qiwu:哪里
# 周围有什么
AROUND_THINGS|havewhat_thing|+旁边:吗+旁边:呢+这里:呢+这里:吗+附近:吗+周围:吗+地方:啊+地点:啊+周围:呀
AROUND_THINGS|havewhat_vv|+这:有
AROUND_THINGS|place_have_something|+这里:什么
# 周围有什么人
AROUND_NPC|place_have_something|+这里:谁+里面:人+里面:谁+附近:人+附近:谁+qiwu:附近+周围:谁+周围:人+旁边:人+旁边:谁+qiwu:周围+谁:那
AROUND_NPC|place_have_something|+这里:谁+里面:人+里面:谁+附近:人+附近:谁+qiwu:附近+周围:谁+周围:人+旁边:人+旁边:谁+qiwu:周围+谁:那+这:谁+这:人
# 周围有什么物品
AROUND_ITEM|place_have_something|+周围:物品+旁边:物品+旁边:东西+周围:东西+附近:物品+附近:东西+这里:物品+这里:东西+qiwu:物品+里面:物品+里面:东西+里面:什么
AROUND_ITEM|havewhat_thing|+周围:物品+旁边:物品+旁边:东西+周围:东西+附近:物品+附近:东西+这里:物品+这里:东西+qiwu:物品+里面:物品+里面:东西+里面:什么
AROUND_ITEM|havewhat_thing|+周围:物品+旁边:物品+旁边:东西+周围:东西+附近:物品+附近:东西+这里:物品+这里:东西+qiwu:物品+里面:物品+里面:东西+里面:什么+这:物品+这:东西
# 周围有什么地方
......@@ -44,14 +45,12 @@ AROUND_NPC_CLASS|havewhat_thing|+周围:name+附近:name+旁边:name
# 周围有什么物品类别
AROUND_ITEM_CLASS|havewhat_thing|+周围:name+附近:name+旁边:name
# 我有什么
WHAT_ITEM_I_HAVE|place_have_something|+qiwu:什么+qiwu:东西+qiwu:物品+qiwu:装备+qiwu:补给
# 去xx
GO_TO|do_what_vn|+去:name+到:name
GO_TO|do_what_vn|+去:name+到:name+回:name
# npc在哪里
......@@ -62,43 +61,62 @@ ITEM_LOCATION|something_where|+哪里:name+哪:name+地方:name+地点:name+位
# 怎么找到npc
HOW_FIND_NPC|want_known_zenmezuo_vn|+找到:name
HOW_FIND_NPC|want_known_zenmezuo_vn|+找到:name+找回:name+拿到:name
#怎么找到物品
HOW_FIND_ITEM|want_known_zenmezuo_vn|+找到:name
HOW_FIND_ITEM|want_known_zenmezuo_vn|+找到:name+找回:name+拿到:name
# 怎么去XXX
HOW_TO_THERE|want_known_zenmezuo_vn|默认
# 你是谁
WHO_YOU_ARE|people_shishui|+botname:谁+botname:干嘛+那个人:谁+人:谁+botname:是+人:是+谁:说话+谁:人
# 任务是什么
TASK_IS_WHAT|something_iswhat|+什么:任务
TASK_IS_WHAT|shenme_shi_shenme|+qiwu:任务
# npc的属性是多少
NPC_ATTR|shuliang_1|+name:attrName
# 物品的属性是多少
ITEM_ATTR|shuliang_1|+name:attrName
# --------------------------------------------------------------------------
# --------------------------------------------------------------------------
# 沙滩上有什么人
WHAT_NPC_IN_LOCATION|havewhat_thing|+name:人
WHAT_NPC_IN_LOCATION|place_have_something|+name:谁+name:人
# xx上有什么东西
WAHT_ITEM_IN_LOCATION|havewhat_thing|+name:物品+name:东西+name:地方+name:位置
WAHT_ITEM_IN_LOCATION|havewhat_thing|+name:物品+name:东西+name:地方+name:位置+name:地点
# 地点上有什么
WHAT_THINGS_IN_LOCATION|have_what_thing|地点
# xx上有什么
WHAT_THINGS_IN_LOCATION|havewhat_vv|+name:有
# 物品是什么
ITEM_INTRO|something_iswhat|+什么:name+name:东西
# 你是谁
WHO_YOU_ARE|zhiwen|+botname:谁+botname:干嘛+那个人:谁+人:谁+botname:是+人:是
# 任务是什么
TASK_IS_WHAT|something_iswhat|+什么:任务
TASK_IS_WHAT|shenme_shi_shenme|+qiwu:任务
# npc有什么
WHAT_NPC_HAVE|havewhat_vv|+name:有+name:拥有+name:带有+name:带
# npc的属性是多少
NPC_ATTR|shuliang_1|+name:attrName
# 我是谁
WHO_I_AM|people_shishui|+谁:qiwu
# npc是谁
NPC_INTRO|people_shishui|+谁:name
# 物品的属性是多少
ITEM_ATTR|shuliang_1|+name:attrName
# tcq new add--------------------------------------
# 物品的作用
ITEM_INTRO|shishenme_1|+干嘛:用+干什么:用
......@@ -180,6 +180,15 @@ public class Config {
public static long CHATCACHE_TIME_OUT;
//-----------------话术----------------
public static String SCRIPT_ITEM_INTRO = null;
public static String SCRIPT_NPC_INTRO = null;
public static String SCRIPT_ITEM_IN_PLACE = null;
public static String SCRIPT_NPC_IN_PLACE = null;
public static String SCRIPT_ALL_IN_PLACE = null;
//script_item_intro
}
......@@ -169,7 +169,7 @@ public class RecoveryServlet extends HttpServlet {
batchUpdate(botAccount, completeConfigText.toString(), context, true);
ape = new ActionPostElem(botId, botName, actionUtils.generateCompleteActionText(receiveParameters, actionTextList), auth, GAME_BOT_CATEGORY,conditionIdPair);
actionUtils.postAction(ape);
actionUtils.postAction(ape, null);
intervalStatus = actionUtils.intervalStatus;
......
......@@ -146,8 +146,9 @@ public class ActionUtils {
Integer botId = parameters.getInteger("botId");
BotInfo botInfo = helper.queryBotInfo(botId);
Boolean bothValue = true;
String styleText = "", serviceURL = "", elements[], conditionName;
String styleText = "", serviceURL = "", elements[], conditionName, finalText;
Set<String> conditionNameSet = new HashSet<String>();
Map<String, String> macroMap = null;
StringBuffer postActionText = null, processText = new StringBuffer(), fullActionText = new StringBuffer();
if(botInfo == null){
......@@ -201,9 +202,23 @@ public class ActionUtils {
postActionText.append(actionText);
}
postActionText.append("\r\n\r\n");
return postActionText.toString();
macroMap = getKeywordMacroMap(botId);
finalText = postActionText.toString();
//System.out.println(finalText);
for(String macro:macroMap.keySet()){
//专门替换三元组前面
System.out.println(macro + ":替换");
finalText = finalText.replace(macro + ",", macroMap.get(macro) + ",");
}
return finalText;
}
......@@ -265,6 +280,28 @@ public class ActionUtils {
}
/**
* 从关键词单元获取宏定义
* @return
*/
public Map<String, String>getKeywordMacroMap(Integer botId){
String keywordtText = engine.queryKeywordUnitText(botId);
Map<String ,String> macroMap = new HashMap<String, String>();
String pair[] = null;
for(String line:keywordtText.split("\r\n")){
//System.out.println(line);
if(line.startsWith("++")){
pair = line.split("\\|");
macroMap.put(pair[0], pair[1]);
//System.out.println("put" + pair[0] + pair[1]);
}
}
return macroMap;
}
public void queryCategory(JSONObject parameters){
int botId = parameters.getInteger("botId");
String[] categoryChain;
......@@ -322,7 +359,7 @@ public class ActionUtils {
finalText = generateCompleteActionText(parameters, conditionTextList);
ape.setActionText(finalText);
postAction(ape);
postAction(ape, null);
}
......@@ -551,6 +588,12 @@ public class ActionUtils {
if (line.startsWith("options|") || line.trim().equals("") || line.startsWith("idlelimit"))
continue;
//修改关键词单元时应该修改version
if(line.startsWith("$version")) {
newKeywords.append("$version|").append(System.currentTimeMillis()).append("\r\n");
continue;
}
newKeywords.append(line);
if(line.startsWith("++")){
keywordPair = line.split("\\|");
......@@ -596,7 +639,7 @@ public class ActionUtils {
ActionPostElem ape = new ActionPostElem("", -1, data.getString("botName_yhm"), data.getString("catName"), authorization, data.getString("botType"));
postAction(ape);
postAction(ape, null);
if(intervalStatus.getStatus() == 1){
((JSONObject)intervalStatus.getExtraData()).put("botId", ape.getBotId());
......@@ -703,7 +746,7 @@ public class ActionUtils {
* @param ape
* @return
*/
public void postAction(ActionPostElem ape){
public void postAction(ActionPostElem ape, String gameEditorSessionId){
String url = CONDITION_BACKEND_URL + "/post/actions";
JSONObject retData = null;
Integer statusCode = 0;
......@@ -724,6 +767,10 @@ public class ActionUtils {
if(!ape.getBotType().equals(""))
postData.put("project", ape.getBotType());
if(gameEditorSessionId != null){
postData.put("gameEditorSessionId", gameEditorSessionId);
}
try {
retData = SimpleUtil.postJSON(url, postData, ape.getAuthorization());
......@@ -844,15 +891,38 @@ public class ActionUtils {
}
}
parameters.put("conditionData", conditionData);
finalText = generateCompleteActionText(parameters, actionTextList);
ape = new ActionPostElem(botId, botName, finalText, auth, "", conditionPostPair);
postAction(ape);
//第一次提交,获取关键词单元的数据
ape = new ActionPostElem(botId, botName, "", auth, "", conditionPostPair);
postAction(ape, parameters.getString("gameEditorSessionId"));
if(intervalStatus.getStatus() == 1) {
helper.batchInsertCondition(conditionList);
//insertCondition(parameters);
if (intervalStatus.getStatus() == 1) {
engine.updateWelcomeText(botId, parameters.getString("welcome"));
updateKnowledgeUnit(botId, new HashMap<String, String>() {{
put("options", OPTIONS);
put("idlelimit", IDLE_LIMIT);
}}, macroAppendMap, parameters.getString("POS"));
}
}
if(intervalStatus.getStatus() == 1) {
finalText = generateCompleteActionText(parameters, actionTextList);
//替换宏定义后生成完整的action文本再提交一次
ape = new ActionPostElem(botId, botName, finalText, auth, "", conditionPostPair);
postAction(ape, parameters.getString("gameEditorSessionId"));
if (intervalStatus.getStatus() == 1) {
engine.updateWelcomeText(botId, parameters.getString("welcome"));
updateKnowledgeUnit(botId, new HashMap<String, String>() {{
......@@ -903,25 +973,39 @@ public class ActionUtils {
String repeatKeywords = conditionJson.getJSONArray("repeatList").getJSONObject(0).getString("repeatKeywords").split("-")[0];
String extraKeywords = Joiner.on("+").join(conditionExtraKeywords.get(conditionName + "_head"));
//condition原来的值域是一个宏定义
if(relationHead.startsWith("++")){
if(macroAppendMap.containsKey(relationHead)){
macroAppendMap.get(relationHead).append(extraKeywords);
}else{
macroAppendMap.put(relationHead, new StringBuffer(extraKeywords));
//要添加的关键词不为空
if(!extraKeywords.equals("")) {
if (macroAppendMap.containsKey(relationHead)) {
macroAppendMap.get(relationHead).append(extraKeywords);
} else {
macroAppendMap.put(relationHead, new StringBuffer(extraKeywords));
}
}
}else{
conditionJson.put("relationHead", extraKeywords);
}
conditionJson.put("relationHead", extraKeywords);
//将三元组头部的限定词替换为游戏中使用的关键词,如果为*,则不替换
//if(!conditionJson.getString("relationHead").equals("*"))
extraKeywords = Joiner.on("+").join(conditionExtraKeywords.get(conditionName + "_tail"));
if(repeatKeywords.startsWith("++")){
if(macroAppendMap.containsKey(repeatKeywords)){
macroAppendMap.get(repeatKeywords).append(extraKeywords);
}else{
macroAppendMap.put(repeatKeywords, new StringBuffer(extraKeywords));
//要添加的关键词不为空
if(!repeatKeywords.equals("")) {
if (macroAppendMap.containsKey(repeatKeywords)) {
macroAppendMap.get(repeatKeywords).append(extraKeywords);
} else {
macroAppendMap.put(repeatKeywords, new StringBuffer(extraKeywords));
}
}
}else {
conditionJson.getJSONArray("repeatList").getJSONObject(0).put("repeatKeywords", extraKeywords);
}
conditionJson.getJSONArray("repeatList").getJSONObject(0).put("repeatKeywords", extraKeywords);
return true;
......
......@@ -158,6 +158,9 @@ public class CharacterConstructor extends ElementConstructor {
//WHO_YOU_ARE
queryTypeConfigTermGenerate(keywordMap, "WHO_YOU_ARE", "npc", "queryLastTalker");
//查询xx是谁,输出介绍语
queryTypeConfigTermGenerate(keywordMap, "NPC_INTRO", "npc", "queryNpcIntro");
}catch (Exception e){
operationStatus = 0;
message = "NPC接口处理出现异常";
......
......@@ -118,6 +118,7 @@ public class ItemConstructor extends ElementConstructor {
queryTypeConfigTermGenerate(keywordMap, "WHAT_ITEM_I_HAVE", "goods", "queryPlayerItems");
queryTypeConfigTermGenerate(keywordMap, "HOW_FIND_ITEM", "goods", "queryFindItemWay");
queryTypeConfigTermGenerate(keywordMap, "ITEM_INTRO", "goods", "queryItemIntro");
} catch(Exception e){
operationStatus = 0;
......
......@@ -144,7 +144,8 @@ public class MapConstructor extends ElementConstructor {
// queryTypeConfigTermGenerate(keywordMap, "WHO_IN_THERE", "map", "queryInnerNpcBySite");
queryTypeConfigTermGenerate(keywordMap, "TASK_IS_WHAT", "map", "queryTaskDescription");
queryTypeConfigTermGenerate(keywordMap, "WHAT_THINGS_IN_LOCATION", "map", "queryItemsInPlace");
queryTypeConfigTermGenerate(keywordMap, "WHAT_NPC_IN_LOCATION", "map", "queryNpcInPlace");
queryTypeConfigTermGenerate(keywordMap, "WHAT_THINGS_IN_LOCATION", "map", "queryAllInPlace");
} catch(Exception e){
......
......@@ -75,6 +75,7 @@ public class GetAnswerServlet extends HttpServlet {
userinfo = uiController.userInfoQuery(request.getParameter("bot_name"), context);
if (userinfo != null) {
//获得用户历史信息
ChatCache chatCache = null;
......
......@@ -7,12 +7,12 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
### 输出DEBUG 级别以上的日志文件设置 ###
log4j.appender.D=org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File=vincent_player_debug.log
log4j.appender.D.Append=true
log4j.appender.D.Threshold=DEBUG
log4j.appender.D.layout=org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
#log4j.appender.D=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.D.File=vincent_player_debug.log
#log4j.appender.D.Append=true
#log4j.appender.D.Threshold=DEBUG
#log4j.appender.D.layout=org.apache.log4j.PatternLayout
#log4j.appender.D.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### 输出ERROR 级别以上的日志文件设置 ###
log4j.appender.E=org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File=vincent_player_error.log
......
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