Commit 3225595d by hxw

修复添加话术condition时关键词变量槽没有替换的问题

parent 8d68a55a
...@@ -214,7 +214,7 @@ public class ActionUtils { ...@@ -214,7 +214,7 @@ public class ActionUtils {
//System.out.println(finalText); //System.out.println(finalText);
for(String macro:macroMap.keySet()){ for(String macro:macroMap.keySet()){
//专门替换三元组前面 //专门替换三元组前面
System.out.println(macro + ":替换"); //System.out.println(macro + ":替换");
finalText = finalText.replace(macro + ",", macroMap.get(macro) + ","); finalText = finalText.replace(macro + ",", macroMap.get(macro) + ",");
} }
......
...@@ -44,6 +44,7 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -44,6 +44,7 @@ public class CharacterConstructor extends ElementConstructor {
copyPattern("AROUND_NPC_CLASS"); copyPattern("AROUND_NPC_CLASS");
copyPattern("NPC_ATTR"); copyPattern("NPC_ATTR");
copyPattern("WHO_YOU_ARE"); copyPattern("WHO_YOU_ARE");
copyPattern("NPC_INTRO");
...@@ -74,6 +75,7 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -74,6 +75,7 @@ public class CharacterConstructor extends ElementConstructor {
appendReplacedKeyword("NPC_LOCATION", replaceList); appendReplacedKeyword("NPC_LOCATION", replaceList);
appendReplacedKeyword("HOW_FIND_NPC", replaceList); appendReplacedKeyword("HOW_FIND_NPC", replaceList);
appendReplacedKeyword("NPC_INTRO", replaceList);
//添加别名 //添加别名
if(character.containsKey("nickname")){ if(character.containsKey("nickname")){
...@@ -85,6 +87,7 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -85,6 +87,7 @@ public class CharacterConstructor extends ElementConstructor {
replaceList.get(0)[1] = nickname; replaceList.get(0)[1] = nickname;
appendReplacedKeyword("NPC_LOCATION", replaceList); appendReplacedKeyword("NPC_LOCATION", replaceList);
appendReplacedKeyword("HOW_FIND_NPC", replaceList); appendReplacedKeyword("HOW_FIND_NPC", replaceList);
appendReplacedKeyword("NPC_INTRO", replaceList);
} }
} }
} }
......
...@@ -232,7 +232,7 @@ public class ElementConstructor { ...@@ -232,7 +232,7 @@ public class ElementConstructor {
} }
/** /**
* 将condition的关键词复制一份,然后清空原来关键词 * 将某个意图对应的condition的关键词复制一份,然后清空原来关键词
* @param intent * @param intent
*/ */
public void copyPattern(String intent){ public void copyPattern(String intent){
...@@ -242,7 +242,7 @@ public class ElementConstructor { ...@@ -242,7 +242,7 @@ public class ElementConstructor {
} }
} }
//把查询意图condition关键词模板中的变量槽替换成具体的值
public void appendReplacedKeyword(String intent, List<String[]> replaceList){ public void appendReplacedKeyword(String intent, List<String[]> replaceList){
String pattern, replaceText; String pattern, replaceText;
for(String conditionName:keywordMap.get(intent).toString().split(",")){ for(String conditionName:keywordMap.get(intent).toString().split(",")){
......
...@@ -37,6 +37,7 @@ public class ItemConstructor extends ElementConstructor { ...@@ -37,6 +37,7 @@ public class ItemConstructor extends ElementConstructor {
copyPattern("ITEM_LOCATION"); copyPattern("ITEM_LOCATION");
copyPattern("AROUND_ITEM_CLASS"); copyPattern("AROUND_ITEM_CLASS");
copyPattern("ITEM_ATTR"); copyPattern("ITEM_ATTR");
copyPattern("ITEM_INTRO");
List<String[]> replaceList = new ArrayList<String[]>(); List<String[]> replaceList = new ArrayList<String[]>();
...@@ -56,6 +57,7 @@ public class ItemConstructor extends ElementConstructor { ...@@ -56,6 +57,7 @@ public class ItemConstructor extends ElementConstructor {
appendReplacedKeyword("ITEM_LOCATION", replaceList); appendReplacedKeyword("ITEM_LOCATION", replaceList);
appendReplacedKeyword("HOW_FIND_ITEM", replaceList); appendReplacedKeyword("HOW_FIND_ITEM", replaceList);
appendReplacedKeyword("ITEM_INTRO", replaceList);
if(good.containsKey("nickname")){ if(good.containsKey("nickname")){
for(String nickname:JSONArray.parseArray(good.getJSONArray("nickname").toJSONString(), String.class)){ for(String nickname:JSONArray.parseArray(good.getJSONArray("nickname").toJSONString(), String.class)){
...@@ -65,6 +67,7 @@ public class ItemConstructor extends ElementConstructor { ...@@ -65,6 +67,7 @@ public class ItemConstructor extends ElementConstructor {
replaceList.get(0)[1] = nickname; replaceList.get(0)[1] = nickname;
appendReplacedKeyword("ITEM_LOCATION", replaceList); appendReplacedKeyword("ITEM_LOCATION", replaceList);
appendReplacedKeyword("HOW_FIND_ITEM", replaceList); appendReplacedKeyword("HOW_FIND_ITEM", replaceList);
appendReplacedKeyword("ITEM_INTRO", replaceList);
} }
} }
} }
......
...@@ -120,7 +120,8 @@ public class MapConstructor extends ElementConstructor { ...@@ -120,7 +120,8 @@ public class MapConstructor extends ElementConstructor {
throw new Exception("话术不存在"); throw new Exception("话术不存在");
} }
JSONArray locations = map.getJSONArray("locations"); JSONArray locations = map.getJSONArray("locations");
String userName = (String) gameElements.get("userName");
String userName = gameElements.getString("userName"), locationName;
this.locations = locations; this.locations = locations;
this.question2keyword = question2keyword; this.question2keyword = question2keyword;
//通过邻接表构造邻接矩阵 //通过邻接表构造邻接矩阵
...@@ -143,7 +144,29 @@ public class MapConstructor extends ElementConstructor { ...@@ -143,7 +144,29 @@ public class MapConstructor extends ElementConstructor {
queryTypeConfigTermGenerate(keywordMap, "AROUND_PLACE", "map", "queryAroundPlace"); queryTypeConfigTermGenerate(keywordMap, "AROUND_PLACE", "map", "queryAroundPlace");
// queryTypeConfigTermGenerate(keywordMap, "WHO_IN_THERE", "map", "queryInnerNpcBySite"); // queryTypeConfigTermGenerate(keywordMap, "WHO_IN_THERE", "map", "queryInnerNpcBySite");
queryTypeConfigTermGenerate(keywordMap, "TASK_IS_WHAT", "map", "queryTaskDescription"); queryTypeConfigTermGenerate(keywordMap, "TASK_IS_WHAT", "map", "queryTaskDescription");
queryTypeConfigTermGenerate(keywordMap, "WHAT_THINGS_IN_LOCATION", "map", "queryItemsInPlace");
//如果预先要添加的condition关键词是带有变量的(比如name),那么说明这是一个关键词模板,需要在生成的时候把这些变量替换成具体的值,所以需要想拷贝模板
List<String[]> replaceList = new ArrayList<String[]>(){
{
add(new String[]{"name",""});
}
};
copyPattern("WAHT_ITEM_IN_LOCATION");
copyPattern("WHAT_NPC_IN_LOCATION");
copyPattern("WHAT_THINGS_IN_LOCATION");
for (int i = 0; i < locationNum; i++) {
locationName = locations.getJSONObject(i).getString("name");
replaceList.get(0)[1] = locationName;
//根据模板添加关键词
appendReplacedKeyword("WAHT_ITEM_IN_LOCATION", replaceList);
appendReplacedKeyword("WHAT_NPC_IN_LOCATION", replaceList);
appendReplacedKeyword("WHAT_THINGS_IN_LOCATION", replaceList);
}
queryTypeConfigTermGenerate(keywordMap, "WAHT_ITEM_IN_LOCATION", "map", "queryItemsInPlace");
queryTypeConfigTermGenerate(keywordMap, "WHAT_NPC_IN_LOCATION", "map", "queryNpcInPlace"); queryTypeConfigTermGenerate(keywordMap, "WHAT_NPC_IN_LOCATION", "map", "queryNpcInPlace");
queryTypeConfigTermGenerate(keywordMap, "WHAT_THINGS_IN_LOCATION", "map", "queryAllInPlace"); queryTypeConfigTermGenerate(keywordMap, "WHAT_THINGS_IN_LOCATION", "map", "queryAllInPlace");
......
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