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.JConfig; 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 pattern1 = keywordMap.get("item_location_pattern").toString(); String category, name, className, description, attrValue; JSONArray goods = gameElements.getJSONArray("goods"); Map attribute = null; Iterator attrIter = null; HashSet classSet = new HashSet(); keywordMap.putIfAbsent("item_wenzainali", new StringBuffer()); keywordMap.putIfAbsent("item_shishenme", new StringBuffer()); keywordMap.putIfAbsent("item_know_exist_what", new StringBuffer()); keywordMap.putIfAbsent("item_nums", new StringBuffer()); //与物品属性查询相关的所有condition String attrRelateConditions[] = {"nums", "shishenme"}; //与物品类查询相关的所有condition String classRelateConditions[] = {"know_exist_what" }; String locationRelateConditions[] = {"wenzainali"}; //如何找到×××××× ,这样的condition String findRelateConditions[] = {"want_know_zenmezuo"}; String findPattern = keywordMap.get("find_pattern").toString(); StringBuffer classKeywords = new StringBuffer(); for (JSONObject good : goods.toJavaList(JSONObject.class)) { name = (String) good.get("name"); //添加词性 if(!name.equals("")) POS.append("=" + name + "|名词\r\n"); className = (String) good.get("class"); if(!className.equals("")) POS.append("=" + className + "|名词\r\n"); keywordMap.get("item_" + locationRelateConditions[0]).append(pattern1.replace("name", name)); //添加所有物品类别 if (!classSet.contains(className)) { classSet.add(className); //添加周围有什么士兵等关于类别的关键词 classKeywords.append("+周围:" + className + "+附近:" + className); } attribute = gameElements.toJavaObject(good.getJSONObject("attr"), Map.class); for(String attrName: attribute.keySet()){ if(!attrName.equals("")) POS.append("=" + attrName + "|名词\r\n"); attrValue = attribute.get(attrName); for(String condition: attrRelateConditions){ keywordMap.get("item_" + condition).append("+" + name + ":" + attrName); } } } //与地点查询相关的condition for(String conditionName: locationRelateConditions){ jConfig = new JConfig( conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString() + "," + "zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ", "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", " ", "goods_query:queryLocationByConditionName:" + conditionName ); JConfig.activateCopy(jConfig, jConfigList, "item"); //jConfigList.add(jConfig); jConfig = new JConfig( conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ", "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", " ", "goods_query:queryLocationByConditionName:" + conditionName ); JConfig.activateCopy(jConfig, jConfigList, "item"); } //根据根据物品名字和属性查询属性值 for (String conditionName : attrRelateConditions) { jConfig = new JConfig( conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ", "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", " ", "goods_query:queryAttrByGoodsName:" + conditionName ); JConfig.activateCopy(jConfig, jConfigList, "item"); } //根据类名查询周围所有实例 for (String conditionName : attrRelateConditions) { jConfig = new JConfig( conditionName + "::match-Include=" + classKeywords, " ", "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", " ", "goods_query:queryAroundGoodsByClassName:" + conditionName ); JConfig.activateCopy(jConfig, jConfigList, "item"); } } catch(Exception e){ operationStatus = 0; message = "物品处理出现异常"; return; } } }