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 CharacterConstructor extends ElementConstructor { public CharacterConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet exceptRelation, StringBuffer POS) { super(); this.helper = helper; this.botId = botId; this.botAccount = botAccount; this.exceptRelation = exceptRelation; this.skipCount = skipCount; this.POS = POS; } public void construct(JSONObject gameElements, UserInfo userinfo) { String category, name, className, description, attrName, attrValue; try { JSONArray allNPC = gameElements.getJSONArray("npc"); Map attribute = null; Iterator attrIter = null; HashSet classSet = new HashSet(); //与npc属性相关的所有condition ArrayList relateConditions = new ArrayList() { { add("wenzainali"); add("shishenme"); } }; //与npc类相关的所有condition ArrayList classRelateConditions = new ArrayList() { { add("know_exist_what"); } }; //在condition的三元组中添加与NPC相关的关键词 String conditionValue = "哪里:人称", repValue; StringBuffer keywords = new StringBuffer(); StringBuffer classKeywords = new StringBuffer(); for (JSONObject character : allNPC.toJavaList(JSONObject.class)) { name = (String) character.get("name"); if(!name.equals("")) POS.append("=" + name + "|人名\r\n"); className = (String) character.get("class"); if(!className.equals("")) POS.append("=" + className + "|人名\r\n"); if (!classSet.contains(className)) { classSet.add(className); classKeywords.append("+周围:" + className + "+附近:" + className); } attribute = gameElements.toJavaObject(character.getJSONObject("attr"), Map.class); attrIter = attribute.keySet().iterator(); repValue = conditionValue.replace("人称", name); keywords.append("+" + repValue); while (attrIter.hasNext()) { attrName = attrIter.next(); if(!attrName.equals("")) POS.append("=" + attrName + "|名词\r\n"); attrValue = attribute.get(attrName); } System.out.println(name); } //根据根据NPC名字和属性查询属性值 for (String conditionName : relateConditions) { jConfig = new JConfig( conditionName + "::match-Include=" + keywords, " ", "match,return-0", "【{智能助手-2}】{NPC_query-2}", "yaobuyao", "NPC_query:queryAttrByNPCName:" + conditionName ); jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); } //根据根据NPC类别和地点属性查询所有NPC实例 for (String conditionName : relateConditions) { jConfig = new JConfig( conditionName + "::match-Include=" + classKeywords, " ", "match,return-0", "【{智能助手-2}】{NPC_query-2}", "yaobuyao", "NPC_query:queryAroundNpcByClassName:" + conditionName ); jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); } }catch (Exception e){ operationStatus = 0; message = "NPC接口处理出现异常"; return; } } }