/** * See {@link #update(List, List)}. Deleting an {@link Update} is calling * update with the add and delete lists reversed. * * @param update * The update to be processed. * @throws MSTQueryException */ public Result delete(Update update) throws MSTQueryException { return update(update.getDeleteList(), update.getAddList()); }
/** * * @param content */ public void setContent(Update content) { this.content = content; this.free = this.content.getFreeVar(); }
/** * The update is removed from the beliefbase of the agent. * * @param update * The belief to be removed. * @param generator * the channel to report executed actions to . * @param agent * An optional agent to do the deletion (in a model) for; the current * agent is used otherwise. * @throws MSTDatabaseException * @throws MSTQueryException */ public List<Result> delete(Update update, ExecutionEventGeneratorInterface generator, AgentId... agent) throws MSTDatabaseException, MSTQueryException { generator.event(Channel.DELETE_START, update, update.getSourceInfo(), "delete %s", update); List<Result> result = this.mentalState.delete(update, agent); generator.event(Channel.DELETE_END, update, update.getSourceInfo(), "deleted %s", update); return result; }
Update update = ((InsertAction) action).getUpdate(); this.beliefUpdates.add(update); this.beliefQueries.add(update.toQuery()); this.insertUpdates.add(update); Update update = ((DeleteAction) action).getUpdate(); this.beliefUpdates.add(update); this.beliefQueries.add(update.toQuery()); this.deleteUpdates.add(update); this.goalQueries.add(((AdoptAction) action).getUpdate().toQuery()); this.adoptUpdates.add(((AdoptAction) action).getUpdate()); this.goalQueries.add(((DropAction) action).getUpdate().toQuery()); this.dropUpdates.add(((DropAction) action).getUpdate());
/** * Inserts a new goal into the goal base. Checks whether the formula (update) * already occurs in the goal base. * * Public as used by the {@link GOALMentalStateConverter}... * * @param update * The update to be inserted. * @return true if anything changed. * @throws MSTDatabaseException */ public Result insert(Update update) throws MSTDatabaseException { Result result = this.owner.createResult(BASETYPE.GOALBASE, getName()); SingleGoal goal = createGoal(update); if (this.goals.add(goal)) { result.added(update.getAddList()); } return result; }
@Override public Update visitGoalDrop(String krFragment, SourceInfo info) throws ParserException { Update drop = super.visitGoalAdopt(krFragment, info); if (drop != null && !drop.getDeleteList().isEmpty()) { // TODO: message(properties) system throw new ParserException("cannot drop negative facts", info); } return drop; }
@Override public SendAction applySubst(Substitution substitution) { return new SendAction(this.operator, (getSelector() == null) ? null : getSelector().applySubst(substitution), (getParameters() == null || getParameters().isEmpty()) ? null : getParameters().get(0).applySubst(substitution), getSourceInfo()); }
/** * A message is considered to be closed if its content is closed, or if it is an * interrogative (and variables are allowed in the message content). * * @return {@code true} if the content of the message does not have any free * variables, or the message is an interrogative; {@code false} * otherwise. */ public boolean isClosed() { return this.content.isClosed() || this.mood == SentenceMood.INTERROGATIVE; }
/** * Implements the blind commitment strategy of a GOAL agent. It removes * goals when they are believed to be achieved completely. * * @return list of goals achieved and removed (per goalbase) * @throws MSTDatabaseException * @throws MSTQueryException */ List<Result> updateGoalState() throws MSTQueryException, MSTDatabaseException { List<Result> results = new LinkedList<>(); for (GoalBase goalbase : this.goalBases) { // Gather the actual goals matching the update in this base List<SingleGoal> goalsToBeRemoved = new LinkedList<>(); for (SingleGoal goal : goalbase.getGoals()) { Set<Substitution> check = this.mentalBases.get(BASETYPE.BELIEFBASE).query(goal.getGoal().toQuery()); if (!check.isEmpty()) { goalsToBeRemoved.add(goal); } } // Actually remove the goals (if any) if (!goalsToBeRemoved.isEmpty()) { Result result = this.owner.createResult(BASETYPE.GOALBASE, goalbase.getName()); for (SingleGoal goal : goalsToBeRemoved) { result.merge(goalbase.remove(goal)); } results.add(result); } } return results; }
/** * @param goal * The goal to remove and clean up. * @return True when the remove was successful. * @throws MSTQueryException * @throws MSTDatabaseException */ Result remove(SingleGoal goal) throws MSTQueryException, MSTDatabaseException { Result result = this.owner.createResult(BASETYPE.GOALBASE, getName()); if (this.goals.remove(goal)) { result.removed(goal.getGoal().getAddList()); goal.cleanUp(); } return result; }
@Override public Update visitGoalAdopt(String krFragment, SourceInfo info) throws ParserException { Update adopt = super.visitGoalAdopt(krFragment, info); if (adopt != null && !adopt.getDeleteList().isEmpty()) { // TODO: message(properties) system throw new ParserException("cannot adopt negative facts", info); } return adopt; }
@Override public DeleteAction applySubst(Substitution substitution) { return new DeleteAction((getSelector() == null) ? null : getSelector().applySubst(substitution), (getParameters() == null || getParameters().isEmpty()) ? null : getParameters().get(0).applySubst(substitution), getSourceInfo()); } }
/** * See {@link #update(List, List)}. * * @param update * The update to be processed. * @throws MSTQueryException */ public Result insert(Update update) throws MSTQueryException { return update(update.getAddList(), update.getDeleteList()); }
/** * Drops all goals that entail the goal to be dropped. * * @param dropgoal * goal to be dropped. * @return A (possibly empty) list of goals that have been dropped. * @throws MSTDatabaseException */ Result drop(Update dropgoal) throws MSTQueryException, MSTDatabaseException { // Gather the actual goals matching the update List<SingleGoal> goalsToBeDropped = new LinkedList<>(); for (SingleGoal goal : this.goals) { Set<Substitution> dropCheck = goal.query(dropgoal.toQuery()); if (!dropCheck.isEmpty()) { goalsToBeDropped.add(goal); } } // Actually remove the goals (from the collection & clean-up themselves) Result result = this.owner.createResult(BASETYPE.GOALBASE, getName()); for (SingleGoal goal : goalsToBeDropped) { result.merge(remove(goal)); } return result; }
/** * Extracts relevant info for validation. */ private void processInfo() { // Extract relevant info from referenced files. this.knowledge.addAll(this.program.getKnowledge()); this.beliefs.addAll(this.program.getBeliefs()); this.goals.addAll(this.program.getGoals()); // Extract relevant info from macros. for (Macro macro : this.program.getMacros()) { processInfoMacro(macro); } // Extract relevant info from rules. for (Rule rule : this.program.getRules()) { processInfoRule(rule); } // Add goals in referenced files as goal definitions. for (Query query : this.program.getGoals()) { this.goalDbfs.addAll(query.toUpdate().getAddList()); } } }
public ActionPostCondition applySubst(Substitution subst) { return new ActionPostCondition((getPostCondition() == null) ? null : getPostCondition().applySubst(subst), isNegative(), getSourceInfo()); }
/** * Goals in goal base associated with the agent that entail the given goal are * removed. * * @param update * The goal to be dropped. * @param agent * An optional agent to do the drop (in a model) for; the current * agent is used otherwise. * @throws MSTDatabaseException * @throws MSTQueryException */ public List<Result> drop(Update update, ExecutionEventGeneratorInterface generator, AgentId... agent) throws MSTDatabaseException, MSTQueryException { generator.event(Channel.DROP_START, update, update.getSourceInfo(), "drop %s", update); List<Result> dropped = this.mentalState.drop(update, agent); generator.event(Channel.DROP_END, update, update.getSourceInfo(), "dropped %s", update); return dropped; }
postvars.addAll(positivePostcondition.getPostCondition().getFreeVar()); postvars.addAll(negativePostcondition.getPostCondition().getFreeVar());
/** * Check that no beliefs are inserted/deleted that are already knowledge * * @param knowledgeDefined * @param knowledgeDeclared * @param beliefUpdates * all belief updates, both from inserts, deletes, and actionspecs. * @throws ParserException */ private void checkNoBeliefsInsertedAsKnowledge(Map<String, SourceInfo> knowledgeDefined, Map<String, SourceInfo> knowledgeDeclared, Set<Update> beliefUpdates) { for (Update update : beliefUpdates) { checkNoPredicatesBeliefAndKnowledge(knowledgeDefined, knowledgeDeclared, update.getAddList()); checkNoPredicatesBeliefAndKnowledge(knowledgeDefined, knowledgeDeclared, update.getDeleteList()); } }
/** * Extracts relevant info for validation. */ private void processInfo() { // Extract relevant info from referenced files. this.knowledge.addAll(this.program.getKnowledge()); this.beliefs.addAll(this.program.getBeliefs()); // Extract relevant info from action specifications. for (UserSpecAction action : this.program.getActionSpecifications()) { for (MentalLiteral literal : getBeliefLiterals(action.getPrecondition())) { this.beliefQueries.add(literal.getFormula()); } if (action.getPositivePostcondition() != null) { this.beliefQueries.add(action.getPositivePostcondition().getPostCondition().toQuery()); } if (action.getNegativePostcondition() != null) { this.beliefQueries.add(action.getNegativePostcondition().getPostCondition().toQuery()); } } } }