public ActionPostCondition applySubst(Substitution subst) { return new ActionPostCondition((getPostCondition() == null) ? null : getPostCondition().applySubst(subst), isNegative(), getSourceInfo()); }
/** * 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()); } } } }
@Override public ActionPostCondition visitPost(PostContext ctx) { String krFragment = (ctx.KR_BLOCK() == null) ? "" : removeLeadTrailCharacters(ctx.KR_BLOCK().getText()); Update post = null; try { CognitiveKR ckr = getCognitiveKR(); SourceInfo info = getSourceInfo(ctx.KR_BLOCK()); info = (info == null) ? null : new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition() + 1, info.getStartIndex() + 1, info.getStopIndex() - 1, info.getSource()); post = ckr.visitBeliefInsert(krFragment, info); reportEmbeddedLanguageErrors(ckr); } catch (ParserException e) { reportParsingException(e); } return (post == null) ? null : new ActionPostCondition(post, false, getSourceInfo(ctx)); }
@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()); }
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); } } }
@Override public ActionPostCondition visitPostadd(PostaddContext ctx) { String krFragment = (ctx.KR_BLOCK() == null) ? "" : removeLeadTrailCharacters(ctx.KR_BLOCK().getText()); Update post = null; try { CognitiveKR ckr = getCognitiveKR(); SourceInfo info = getSourceInfo(ctx.KR_BLOCK()); info = (info == null) ? null : new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition() + 1, info.getStartIndex() + 1, info.getStopIndex() - 1, info.getSource()); post = ckr.visitBeliefInsert(krFragment, info); reportEmbeddedLanguageErrors(ckr); } catch (ParserException e) { reportParsingException(e); } return (post == null) ? null : new ActionPostCondition(post, false, getSourceInfo(ctx)); }
if (positivePostcondition != null && positivePostcondition.getPostCondition() != null) { postvars.addAll(positivePostcondition.getPostCondition().getFreeVar()); if (negativePostcondition != null && negativePostcondition.getPostCondition() != null) { postvars.addAll(negativePostcondition.getPostCondition().getFreeVar());
@Override public ActionPostCondition visitPostdel(PostdelContext ctx) { String krFragment = (ctx.KR_BLOCK() == null) ? "" : removeLeadTrailCharacters(ctx.KR_BLOCK().getText()); Update post = null; try { CognitiveKR ckr = getCognitiveKR(); SourceInfo info = getSourceInfo(ctx.KR_BLOCK()); info = (info == null) ? null : new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition() + 1, info.getStartIndex() + 1, info.getStopIndex() - 1, info.getSource()); post = ckr.visitBeliefDelete(krFragment, info); reportEmbeddedLanguageErrors(ckr); } catch (ParserException e) { reportParsingException(e); } return (post == null) ? null : new ActionPostCondition(post, true, getSourceInfo(ctx)); }
if (target != null) { if (target.getPositivePostcondition() != null) { this.beliefUpdates.add(target.getPositivePostcondition().getPostCondition()); this.beliefUpdates.add(target.getNegativePostcondition().getPostCondition());
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); 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);