@Override public UserSpecAction applySubst(Substitution substitution) { // Apply substitution to action parameters, pre- and post-condition. List<Term> parameters = new ArrayList<>(getParameters().size()); for (Term parameter : getParameters()) { parameters.add(parameter.applySubst(substitution)); } ActionPreCondition precondition = (getFullPreCondition() == null) ? null : getFullPreCondition().applySubst(substitution); ActionPostCondition positivePostcondition = (getPositivePostcondition() == null) ? null : getPositivePostcondition().applySubst(substitution); ActionPostCondition negativePostcondition = (getNegativePostcondition() == null) ? null : getNegativePostcondition().applySubst(substitution); return new UserSpecAction(getName(), parameters, isExternal(), precondition, positivePostcondition, negativePostcondition, getSourceInfo()); }
/** * Add an action specification to this action specification program. * * @param actionSpec * An action specification. */ public void addActionSpecification(UserSpecAction action) { register(action); if (action.getFullPreCondition() != null) { register(action.getPrecondition()); } if (action.getPositivePostcondition() != null) { register(action.getPositivePostcondition()); } if (action.getNegativePostcondition() != null) { register(action.getNegativePostcondition()); } this.actions.add(action); }
@Override public Action convert(UserSpecAction action) throws MSTTranslationException { LinkedList<Parameter> parameters = new LinkedList<>(); for (Term term : action.getParameters()) { parameters.add(convert(term)); } return new Action(action.getName(), parameters); }
protected void reportUnusedVariables() { for (UserSpecAction spec : this.program.getActionSpecifications()) { List<Var> vars = new LinkedList<>(); try { CognitiveKR ckr = getFirstPass().getCognitiveKR(); if (spec.getPrecondition() != null) { for (MentalLiteral literal : spec.getPrecondition().getAllLiterals()) { vars.addAll(ckr.getAllVariables(literal.getFormula())); } } if (spec.getNegativePostcondition() != null) { vars.addAll(ckr.getAllVariables(spec.getNegativePostcondition().getPostCondition())); } if (spec.getPositivePostcondition() != null) { vars.addAll(ckr.getAllVariables(spec.getPositivePostcondition().getPostCondition())); } Set<Var> unique = new LinkedHashSet<>(vars); unique.removeAll(spec.getParameters()); for (Var var : unique) { int occurences = Collections.frequency(vars, var); if (occurences < 2) { getFirstPass().reportWarning(ActionSpecWarning.VARIABLE_UNUSED, var.getSourceInfo(), var.toString()); } } } catch (ParserException e) { getFirstPass().reportParsingException(e); } } }
/** * 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()); } } } }
String signature; for (UserSpecAction actionspec : this.program.getActionSpecifications()) { signature = actionspec.getSignature(); symbol = new ActionSymbol(signature, actionspec, actionspec.getSourceInfo()); if (!this.actionSymbols.define(symbol)) { reportDuplicateActionLabelDfs(signature, symbol); this.actionsDefined.add(actionspec.getSignature());
UserSpecAction action = new UserSpecAction(name, parameters, external, precondition, positivePostcondition, negativePostcondition, getSourceInfo(ctx)); getProgram().addActionSpecification(action); if (!this.actionSymbols.define(new ActionSymbol(action.getSignature(), action, action.getSourceInfo()))) { reportError(ActionSpecError.ACTION_LABEL_ALREADY_DEFINED, ctx, action.getSignature());
/** * Creates a new {@link UserSpecCallAction}, which will focus the agent's * attention to a certain module when executed. * * @param spec * the user spec action that should be called. * @param parameters * the parameters, exactly as used at the caller's side. These * still have to be substituted at runtime against the actual * variable values at that time and then renamed into the space * of the {@link #actionSpec}. */ public UserSpecCallAction(UserSpecAction spec, List<Term> parameters, SourceInfo info) { super(spec.getName(), info); for (Term term : parameters) { addParameter(term); } this.actionSpec = spec; }
resolvedAction = new UserSpecCallAction(target, usedAction.getParameters(), usedAction.getSourceInfo()); if (target != null) { if (target.getPositivePostcondition() != null) { this.beliefUpdates.add(target.getPositivePostcondition().getPostCondition()); if (target.getNegativePostcondition() != null) { this.beliefUpdates.add(target.getNegativePostcondition().getPostCondition());
@Override public MentalStateCondition getPrecondition() { return this.actionSpec.getPrecondition(); }
usedActions.add(action.getSignature()); unusedActions.add(action.getSignature());
public ActionPreCondition getFullPreCondition() { return this.actionSpec.getFullPreCondition(); } }
/** * Applies the substitution to the parameters of this action and to the * target module associated with the action. Assumes a target module has * been associated with this action. * * @return Instantiated module call action, where free variables in * parameters have been substituted with terms from the * substitution. */ @Override public Action<Term> applySubst(Substitution substitution) { // Apply substitution to parameters. List<Term> parameters = new ArrayList<>(getParameters().size()); for (Term term : getParameters()) { parameters.add(term.applySubst(substitution)); } // Create new focus action with instantiated parameters. return new UserSpecCallAction((getSpecification() == null) ? null : getSpecification().applySubst(substitution), parameters, getSourceInfo()); }
protected void doCreateGraph(UserSpecAction subject) { for (MentalLiteral formula : subject.getPrecondition().getAllLiterals()) { try { super.getGraph().add(formula.getFormula()); if (subject.getPositivePostcondition() != null) { for (DatabaseFormula formula : subject.getPositivePostcondition().getPostCondition().getAddList()) { try { super.getGraph().add(formula, true, false); for (DatabaseFormula formula : subject.getPositivePostcondition().getPostCondition().getDeleteList()) { try { super.getGraph().add(formula, false, true); if (subject.getNegativePostcondition() != null) { for (DatabaseFormula formula : subject.getNegativePostcondition().getPostCondition().getDeleteList()) { try { super.getGraph().add(formula, true, false); for (DatabaseFormula formula : subject.getNegativePostcondition().getPostCondition().getAddList()) { try { super.getGraph().add(formula, false, true);
ActionSpecProgram actionspecs = (ActionSpecProgram) this.program.getRegistry().getProgram(file); for (UserSpecAction actionspec : actionspecs.getActionSpecifications()) { String signature = actionspec.getSignature(); Symbol symbol = new ActionSymbol(signature, actionspec, actionspec.getSourceInfo()); if (!this.actionSymbols.define(symbol)) { reportDuplicateActionLabelDfs(signature, symbol); this.actionsDefined.add(actionspec.getSignature());
for (MentalLiteral formula : userspec.getPrecondition().getAllLiterals()) { super.getGraph().add(formula.getFormula());
for (UserSpecAction action : this.unusedActionDefinitions .toArray(new UserSpecAction[this.unusedActionDefinitions.size()])) { if (this.actionCalls.contains(action.getSignature())) { this.unusedActionDefinitions.remove(action);
reportWarning(MASWarning.ACTION_UNUSED, action.getSourceInfo(), action.getSignature());