Commit d30c1983 by 赵国君

停留,合并剧情等问题修复

parent 8b6893aa
......@@ -846,18 +846,18 @@ public class ActionUtils {
conditionExtraKeywords.putIfAbsent(DEFAULT_CONDITION + "_head", new HashSet<String>());
conditionExtraKeywords.putIfAbsent(DEFAULT_CONDITION + "_tail", new HashSet<String>());
for(int i = 1;i < 10;i++){
for(int i = 1;i < 100;i++){
//给condition的名字添加后缀,因为游戏中可能用到condition的复制,但值域和名字不一样
if(i == 1)
postfix = "";
else
postfix = String.valueOf(i);
postfix = "_" + String.valueOf(i);
activeFlag = "0";
conditionJson = (JSONObject) patternConditionJson.clone();
conditionName = conditionJson.getString("conditionName") + postfix;
conditionName2 = conditionName + "_independent";
conditionName2 = conditionName + "_indep";
if(!conditionExtraKeywords.containsKey(conditionName + "_tail")){ //如果没有用到这个condition,就跳过
if(!conditionExtraKeywords.containsKey(conditionName2 + "_tail"))
......
......@@ -167,9 +167,9 @@ public class ConfigTermText implements Cloneable{
}
public ConfigTermText(List<Premise> curPremise, List<Premise> hisPremise, Map<String, String> updateKnowledge, String extraCP, String extraHP, String extraUK, String feature, String reply, String nextStep, String auxiliaryPriority) {
this.curPremise = appendPremiseStr(curPremise, extraCP);
this.hisPremise = appendPremiseStr(hisPremise, extraHP);
public ConfigTermText(List<Premise> curPremise, List<Premise> hisPremise, Map<String, String> updateKnowledge, String extraCP, String extraHP, String extraUK, String feature, String reply, String nextStep, String auxiliaryPriority, Map<String ,Integer> gNameCount) {
this.curPremise = appendPremiseStr(curPremise, extraCP, gNameCount);
this.hisPremise = appendPremiseStr(hisPremise, extraHP, gNameCount);
this.updateKnowledge = appendKnowledgeStr(updateKnowledge, extraUK);
this.feature = feature;
this.reply = reply;
......@@ -177,26 +177,28 @@ public class ConfigTermText implements Cloneable{
this.auxiliaryPriority = auxiliaryPriority;
}
public String appendPremiseStr(List<Premise> premises, String extraPremise) {
public String appendPremiseStr(List<Premise> premises, String extraPremise, Map<String ,Integer> gNameCount) {
StringBuffer sb = new StringBuffer();
String premiseStr = "", conditionName;
Map<String ,Integer> nameCount = new HashMap<String , Integer>();
for (Premise premise : premises){
conditionName = premise.getConditionName();
if(conditionName.startsWith("npc_") ||
conditionName.startsWith("goods_") ||
conditionName.startsWith("globalVariable_") ||
conditionName.startsWith("map_"))
conditionName.startsWith("map_") ||
conditionName.startsWith("start_options") ||
conditionName.startsWith("load_game_by_site")
)
{}
else {
nameCount.putIfAbsent(conditionName, 0);
//nameCount加一
nameCount.put(conditionName, nameCount.get(conditionName) + 1);
//在conditionName后添加count
if(nameCount.get(conditionName) > 1) {
premise.setConditionName(conditionName + nameCount.get(conditionName) + "_independent");
}
gNameCount.putIfAbsent(conditionName, 0);
gNameCount.put(conditionName, gNameCount.get(conditionName) + 1);
if(gNameCount.get(conditionName) > 1 && premise.getAccurateMatch()) {
premise.setConditionName(conditionName + "_" + gNameCount.get(conditionName));
premise.setAccurateName();
}
}
sb.append(",");
......
package com.qiwu.chatbotbackend.entity;
public class Premise {
private String conditionName = "";
private String cmpType = "";
private String operator = "";
private String keyword = "";
public Premise(String conditionName, String cmpType, String operator, String keyword) {
this.conditionName = conditionName;
this.cmpType = cmpType;
this.operator = operator;
this.keyword = keyword;
if(cmpType == null){
this.cmpType = "match";
}else{
this.cmpType = cmpType;
}
if(operator == null){
this.operator = "Include";
}else{
this.operator = operator;
}
if(cmpType.equals("any")){
this.operator = "Include";
}
}
public String getConditionName() {
return conditionName;
}
public void setConditionName(String conditionName) {
this.conditionName = conditionName;
}
public String getCmpType() {
return cmpType;
}
public void setCmpType(String cmpType) {
this.cmpType = cmpType;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
}
package com.qiwu.chatbotbackend.entity;
public class Premise {
private String conditionName = "";
private String cmpType = "";
private String operator = "";
private String keyword = "";
private Boolean accurateMatch = false;
private String plot = "";
private int branch = 0;
public String getPlot() {
return plot;
}
public void setPlot(String plot) {
this.plot = plot;
}
public int getBranch() {
return branch;
}
public void setBranch(int branch) {
this.branch = branch;
}
public Boolean getAccurateMatch() {
return accurateMatch;
}
public void setAccurateMatch(Boolean accurateMatch) {
this.accurateMatch = accurateMatch;
}
public Premise(String conditionName, String cmpType, String operator, String keyword, Boolean accurateMatch) {
this.conditionName = conditionName;
this.cmpType = cmpType;
this.operator = operator;
this.keyword = keyword;
this.accurateMatch = accurateMatch;
if(cmpType == null){
this.cmpType = "match";
}else{
this.cmpType = cmpType;
}
if(operator == null){
this.operator = "Include";
}else{
this.operator = operator;
}
if(cmpType.equals("any")){
this.operator = "Include";
}
if(accurateMatch == null)
{
this.accurateMatch = false;
}
}
public Premise(String conditionName, String cmpType, String operator, String keyword) {
this.conditionName = conditionName;
this.cmpType = cmpType;
this.operator = operator;
this.keyword = keyword;
this.accurateMatch = false;
if(cmpType == null){
this.cmpType = "match";
}else{
this.cmpType = cmpType;
}
if(operator == null){
this.operator = "Include";
}else{
this.operator = operator;
}
if(cmpType.equals("any")){
this.operator = "Include";
}
}
public String getConditionName() {
return conditionName;
}
public void setConditionName(String conditionName) {
this.conditionName = conditionName;
}
public String getCmpType() {
return cmpType;
}
public void setCmpType(String cmpType) {
this.cmpType = cmpType;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
public void setAccurateName() {
this.conditionName = this.conditionName + "_indep";
}
}
package com.qiwu.chatbotbackend.gameDesign;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.ConfigTermText;
import com.qiwu.chatbotbackend.entity.Premise;
import com.qiwu.chatbotbackend.entity.UserInfo;
import java.util.*;
import static com.qiwu.chatbotbackend.Config.Config.*;
public class ListeningConstructor extends ElementConstructor{
public ListeningConstructor(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.keywordMap = keywordMap;
this.POS = POS;
}
public void construct(JSONObject jsonObject, UserInfo userinfo) {
}
public static void cc(String botAccount, JSONObject gameELments, HashMap<String, JSONObject> plotIndex, List<ConfigTermText> configTermTextList){
int size = 0;
String feature, nextPlotId, reply = "", nextCondition = "", nextLocation = "", priority;
String nTaskLineName, lastTaskCondition, lastTaskReply, nextGameStep;
Boolean autoJump = false;
List<Premise> curPremiseList = new ArrayList<Premise>();
List<Premise> hisPremiseList = new ArrayList<Premise>();
JSONArray listeningActions = gameELments.getJSONArray("listeningActions");
JSONObject plotNode = null;
if(listeningActions == null)
return;
size = listeningActions.size();
JSONObject config = null;
for(int i = 0; i < size;i++){
plotNode = null;
autoJump = false;
priority = "2";
feature = "match";
config = listeningActions.getJSONObject(i);
curPremiseList = JSONArray.parseArray(config.getJSONArray("curPremise").toJSONString(), Premise.class);
hisPremiseList = JSONArray.parseArray(config.getJSONArray("hisPremise").toJSONString(), Premise.class);
Map<String, String> updateKnowledge = JSONObject.parseObject(config.getJSONObject("updateKnowledge").toJSONString(), Map.class);
nextPlotId = config.getString("nextPlotId");
if(nextPlotId != null){
plotNode = plotIndex.get(nextPlotId);
}
if(plotNode != null){
reply = plotNode.getString("plotText");
nextCondition = plotNode.getString("conditionName");
nextLocation = plotNode.getString("place");
autoJump = plotNode.getBoolean("autoJump");
if(nextCondition == null || nextCondition.equals("")){
nextCondition = DEFAULT_CONDITION;
}
if(autoJump){
feature = "match,activate:after";
updateKnowledge.put("plot_jump_text", "str+" + reply);
nextCondition = "plot_" + nextPlotId;
reply = "";
}else{
feature = "match";
}
if(config.getString("priority") != null)
priority = config.getString("priority");
updateKnowledge.put(nextLocation + "_activate_by", "");
updateKnowledge.put(nextLocation + "_activate_ready", "0");
updateKnowledge.put("site", nextLocation);
nTaskLineName = String.format(TASK_LINE, nextLocation);
//任务线最后一个condition
lastTaskCondition = String.format(TASK_CONDITION, nextLocation);
lastTaskReply = String.format(TASK_REPLY, nextLocation);
nextGameStep = String.format(GAME_STEP_FORMAT, botAccount,nextPlotId);
updateKnowledge.put(lastTaskCondition, nextCondition);
updateKnowledge.put(lastTaskReply, reply);
updateKnowledge.put(nextPlotId, "1"); //下一步设为1
updateKnowledge.put(nTaskLineName, nextGameStep);
updateKnowledge.put("game_step", nextGameStep);
}else{
feature = "match,return-0";
}
ConfigTermText configTermText = new ConfigTermText(
curPremiseList,
hisPremiseList,
updateKnowledge,
"", "", "", feature, reply, nextCondition, priority
);
// System.out.println("生成:" + curPremiseList.get(0));
configTermTextList.add(configTermText);
}
}
}
package com.qiwu.chatbotbackend.gameDesign;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.ConfigTermText;
import com.qiwu.chatbotbackend.entity.Premise;
import com.qiwu.chatbotbackend.entity.UserInfo;
import java.util.*;
import static com.qiwu.chatbotbackend.Config.Config.*;
public class ListeningConstructor extends ElementConstructor{
public ListeningConstructor(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.keywordMap = keywordMap;
this.POS = POS;
}
public void construct(JSONObject jsonObject, UserInfo userinfo) {
}
public static void cc(String botAccount, JSONObject gameELments, HashMap<String, JSONObject> plotIndex, List<ConfigTermText> configTermTextList){
int size = 0;
String feature, nextPlotId, reply = "", nextCondition = "", nextLocation = "", priority;
String nTaskLineName, lastTaskCondition, lastTaskReply, nextGameStep;
Boolean autoJump = false;
List<Premise> curPremiseList = new ArrayList<Premise>();
List<Premise> hisPremiseList = new ArrayList<Premise>();
JSONArray listeningActions = gameELments.getJSONArray("listeningActions");
JSONObject plotNode = null;
if(listeningActions == null)
return;
size = listeningActions.size();
JSONObject config = null;
for(int i = 0; i < size;i++){
plotNode = null;
autoJump = false;
priority = "2";
feature = "match";
config = listeningActions.getJSONObject(i);
curPremiseList = JSONArray.parseArray(config.getJSONArray("curPremise").toJSONString(), Premise.class);
hisPremiseList = JSONArray.parseArray(config.getJSONArray("hisPremise").toJSONString(), Premise.class);
Map<String, String> updateKnowledge = JSONObject.parseObject(config.getJSONObject("updateKnowledge").toJSONString(), Map.class);
nextPlotId = config.getString("nextPlotId");
if(nextPlotId != null){
plotNode = plotIndex.get(nextPlotId);
}
if(plotNode != null){
reply = plotNode.getString("plotText");
nextCondition = plotNode.getString("conditionName");
nextLocation = plotNode.getString("place");
autoJump = plotNode.getBoolean("autoJump");
if(nextCondition == null || nextCondition.equals("")){
nextCondition = DEFAULT_CONDITION;
}
if(autoJump){
feature = "match,activate:after";
updateKnowledge.put("plot_jump_text", "str+" + reply);
nextCondition = "plot_" + nextPlotId;
reply = "";
}else{
feature = "match";
}
if(config.getString("priority") != null)
priority = config.getString("priority");
updateKnowledge.put(nextLocation + "_activate_by", "");
updateKnowledge.put(nextLocation + "_activate_ready", "0");
updateKnowledge.put("site", nextLocation);
nTaskLineName = String.format(TASK_LINE, nextLocation);
//任务线最后一个condition
lastTaskCondition = String.format(TASK_CONDITION, nextLocation);
lastTaskReply = String.format(TASK_REPLY, nextLocation);
nextGameStep = String.format(GAME_STEP_FORMAT, botAccount,nextPlotId);
updateKnowledge.put(lastTaskCondition, nextCondition);
updateKnowledge.put(lastTaskReply, reply);
updateKnowledge.put(nextPlotId, "1"); //下一步设为1
updateKnowledge.put(nTaskLineName, nextGameStep);
updateKnowledge.put("game_step", nextGameStep);
}else{
feature = "match,return-0";
}
Map<String ,Integer> gNameCount = new HashMap<String , Integer>();
ConfigTermText configTermText = new ConfigTermText(
curPremiseList,
hisPremiseList,
updateKnowledge,
"", "", "", feature, reply, nextCondition, priority, gNameCount
);
// System.out.println("生成:" + curPremiseList.get(0));
configTermTextList.add(configTermText);
}
}
}
......@@ -220,6 +220,9 @@ public class PlotConstructor2 extends ElementConstructor {
int branchSize;
List<Premise> curPremiseList, historyPremiseList;
//condition name 计数
Map<String ,Integer> gNameCount = new HashMap<String , Integer>();
//设置初始化unknown文本
......@@ -487,16 +490,12 @@ public class PlotConstructor2 extends ElementConstructor {
}
//下一部剧情在不同地点时,为了防止到配置文件重复执行,需要加一个标志表示下一步剧情是否已经发生过
// activate_by 下一个地点的剧情是由当前剧情激活的
//_activate_ready 下一个地点的剧情等待被激活
appendKnowledge(extraUK, nextLocation + "_activate_by", id);
appendKnowledge(extraUK, nextLocation + "_activate_ready", "1");
// 如果不能直接到达所在地点,说明剧情1-1和1-2直接存在一个中间结点,这些更新操作会放在中间结点执行(动态生成,方法名:arriveActivatePlot2 这个中间结点会被当做一个监听剧情来处理)
arriveActivatePlot2(jsonObject, id, nextId, nextLocation);
......@@ -506,13 +505,12 @@ public class PlotConstructor2 extends ElementConstructor {
}
}
//System.out.println(branchNode);
//取出作者设定的剧情条件
curPremiseList = JSONArray.parseArray(branchNode.getJSONArray("curPremise").toJSONString(), Premise.class);
historyPremiseList = JSONArray.parseArray(branchNode.getJSONArray("hisPremise").toJSONString(), Premise.class);
addContext(curPremiseList, node.getString("id"), i);
addContext(historyPremiseList, node.getString("id"), i);
//是否将当前识别到的数据加入到已知数据列表
if((Boolean)branchNode.get("includeCurInfo")){
......@@ -525,7 +523,6 @@ public class PlotConstructor2 extends ElementConstructor {
appendFeature(extraFT, branchNode.getString("extraFeature"));
}
//如果符合激活下一个剧情配置文件的操作
if(doActivatePlot(nextAutoJump, location, nextLocation, moveWithPlot) ){
//在配置文件中添加激活的操作
......@@ -540,7 +537,7 @@ public class PlotConstructor2 extends ElementConstructor {
historyPremiseList,
updateKnowledge,
"", extraHP.toString(), extraUK.toString(),
extraFT.toString(), reply, nextCondition, "1"
extraFT.toString(), reply, nextCondition, "1", gNameCount
);
configTermText.setConfigName("plot_" + id, false);
......@@ -569,8 +566,6 @@ public class PlotConstructor2 extends ElementConstructor {
configTermText.setAuxiliaryPriority("3");
configTermTextList.add(configTermText);
//将子结点加入队列
adjId = nextId;
plotEnQueue(queue, id, adjId, nextUnknownText, curAutoJump);
......@@ -585,19 +580,8 @@ public class PlotConstructor2 extends ElementConstructor {
extraUK.setLength(0);
skipText.setLength(0);
arriveUK.setLength(0);
}
}
/**
* ----------------------------------------------------------------------------------------------------
* 剧情不设条件时的处理
......@@ -923,10 +907,10 @@ public class PlotConstructor2 extends ElementConstructor {
//激活下一步剧情的几个条件:1. condition 到沙滩 2. 沙滩_activate_by 沙滩的剧情是有当前剧情激活的 3. 沙滩的剧情处于等待激活的状态 4. 当前地点和沙滩地点相邻或可以直接到达
// 2.3 两个条件是特意加的
curPremiseList.add(new Premise(GOTO_CONDITION, "match", "Include", nextLocation));
hisPremiseList.add(new Premise(nextLocation + "_activate_by", "match", "Include", plotId));
hisPremiseList.add(new Premise(nextLocation + "_activate_ready", "match", "Include", "1"));
hisPremiseList.add(new Premise("isNeighbour:" + GOTO_CONDITION, "match", "Include", "1+3+4"));
curPremiseList.add(new Premise(GOTO_CONDITION, "match", "Include", nextLocation, false));
hisPremiseList.add(new Premise(nextLocation + "_activate_by", "match", "Include", plotId, false));
hisPremiseList.add(new Premise(nextLocation + "_activate_ready", "match", "Include", "1", false));
hisPremiseList.add(new Premise("isNeighbour:" + GOTO_CONDITION, "match", "Include", "1+3+4", false));
//无匹配次数清零
......@@ -1003,20 +987,26 @@ public class PlotConstructor2 extends ElementConstructor {
}
private ConfigTermText createTermExtra2(ConfigTermText term) {
String hPremise = "qa_score::number-Smaller=98";
String featureStr = "match";
String nextStr = " ";
// String featureStr = ",match,includeCurInfo,activate:after";
String configName = term.getConfigName()+"_qa2";
if(term.getFeature().indexOf("activate") != -1) {
nextStr = term.getNextStep() + "," + nextStr;
}
String nextStr = term.getNextStep();
ConfigTermText newTerm = (ConfigTermText)term.clone();
newTerm.setHisPremise(hPremise);
newTerm.setConfigName(configName, false);
newTerm.setFeature(featureStr);
// newTerm.setFeature(featureStr);
newTerm.setNextStep(nextStr);
newTerm.setStatus("sleeping");
//newTerm.setReply("");
return newTerm;
}
private void addContext(List<Premise> premises, String plot, int branch) {
for(Premise pre : premises) {
pre.setPlot(plot);
pre.setBranch(branch);
}
}
}
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