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.UserInfo; import java.util.*; public class ItemConstructor extends ElementConstructor { public ItemConstructor(SqlHelper helper, int botId, String botAccount, Map keywordMap, HashSet 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 gameElements, UserInfo userinfo) { try { String pattern; String category, name, className, description, attrValue; JSONArray goods = gameElements.getJSONArray("goods"); Map attribute = null; Iterator attrIter = null; HashSet classSet = new HashSet(); copyPattern("HOW_FIND_ITEM"); copyPattern("ITEM_LOCATION"); copyPattern("AROUND_ITEM_CLASS"); copyPattern("ITEM_ATTR"); copyPattern("ITEM_INTRO"); List replaceList = new ArrayList(); for (JSONObject good : goods.toJavaList(JSONObject.class)) { name = (String) good.get("name"); replaceList.clear(); replaceList.add(new String[]{"name", name}); List nameList = new ArrayList(); nameList.add(name); //添加词性 className = (String) good.get("class"); appendPOS(POS, name, "名词"); appendPOS(POS, className, "名词"); appendReplacedKeyword("ITEM_LOCATION", replaceList); appendReplacedKeyword("HOW_FIND_ITEM", replaceList); appendReplacedKeyword("ITEM_INTRO", replaceList); if(good.containsKey("nickname")){ for(String nickname:JSONArray.parseArray(good.getJSONArray("nickname").toJSONString(), String.class)){ if(!nickname.equals("")) { appendPOS(POS, nickname, "名词"); nameList.add(nickname); replaceList.get(0)[1] = nickname; appendReplacedKeyword("ITEM_LOCATION", replaceList); appendReplacedKeyword("HOW_FIND_ITEM", replaceList); appendReplacedKeyword("ITEM_INTRO", replaceList); } } } //添加类名称 if (!classSet.contains(className)) { classSet.add(className); replaceList.get(0)[1] = className; appendReplacedKeyword("AROUND_ITEM_CLASS", replaceList); } attribute = gameElements.toJavaObject(good.getJSONObject("attr"), Map.class); replaceList.get(0)[1] = name; replaceList.add(new String[]{"attrName", ""}); for(String attrName: attribute.keySet()){ replaceList.get(1)[1] = attrName; appendPOS(POS, attrName, "名词"); // for(String itemName:nameList) { // for(String conditionName:keywordMap.get("ITEM_ATTR").toString().split(",")){ // //pattern = keywordMap.get("NPC_ATTR_" + conditionName + "_pattern").toString(); // keywordMap.get("ITEM_ATTR_" + conditionName).append("+").append(itemName).append(":").append(attrName); // } // } appendReplacedKeyword("ITEM_ATTR", replaceList); } } // configTermText = new ConfigTermText( // "zainali::match-Include=" + keywordMap.get("WHERE_I_AM_zainali") + "," + // "wenzainali::match-Keyword=" + keywordMap.get("ITEM_LOCATION_wenzainali").toString(), " ", // "match,return-0", "", "yaobuyao", "goods_query:queryLocationByConditionName:wenzainali" // ); // ConfigTermText.activateCopy(configTermText, configTermTextList, "item"); queryTypeConfigTermGenerate(keywordMap, "ITEM_LOCATION", "goods", "queryLocationByConditionName"); //根据根据物品名字和属性查询属性值 queryTypeConfigTermGenerate(keywordMap, "ITEM_ATTR", "goods", "queryAttrByGoodsName"); //根据类名查询周围所有实例 queryTypeConfigTermGenerate(keywordMap, "AROUND_ITEM_CLASS", "goods", "queryAroundGoodsByClassName"); //根据类名查询周围所有实例 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; message = "物品处理出现异常"; e.printStackTrace(); return; } } }