/** * Get a substitution that we can apply to term, such that it will not use given * varsInUse. * * @param varsToBeMadeUnique * vars that have to be renamed if occurring iin the varsInUse list. * @param varsInUse * set of {@link Var}s that are in use * @return A substitution that will standardize apart variables. */ // TODO: Move this method to KR interface? #3430. This is quick fix. private Substitution makeTermVarsUnique(Set<Var> varsToBeMadeUnique, Set<Var> varsInUse) { Set<Var> varsToRename = getSharedVariables(varsToBeMadeUnique, varsInUse); Map<Var, Term> subst = new LinkedHashMap<>(varsToRename.size()); for (Var var : varsToRename) { subst.put(var, var.getVariant(varsInUse)); } return this.program.getKRInterface().getSubstitution(subst); }
public Substitution mgu(Macro other, KRInterface kri) { if (other == null || !getSignature().equals(other.getSignature()) || getParameters().size() != other.getParameters().size()) { return null; } else if (getParameters().isEmpty()) { return kri.getSubstitution(null); } else { // Get mgu for first parameter Substitution substitution = getParameters().get(0).mgu(other.getParameters().get(0)); // Get mgu's for remaining parameters for (int i = 1; i < getParameters().size() && substitution != null; i++) { Substitution mgu = getParameters().get(i).mgu(other.getParameters().get(i)); substitution = substitution.combine(mgu); } return substitution; } }
public Substitution mgu(Action<?> other, KRInterface kri) { if (other == null || !getSignature().equals(other.getSignature()) || getParameters().size() != other.getParameters().size()) { return null; } else if (getParameters().isEmpty()) { return kri.getSubstitution(null); } else { // Get mgu for first parameter Substitution substitution = getParameters().get(0).mgu(other.getParameters().get(0)); // Get mgu's for remaining parameters for (int i = 1; i < getParameters().size() && substitution != null; i++) { Substitution mgu = getParameters().get(i).mgu(other.getParameters().get(i)); substitution = substitution.combine(mgu); } return substitution; } }
generator); for (Substitution tempSubst : tempResult) { currentResults.add(subst.combine(tempSubst)); result.add(this.owner.getKRInterface().getSubstitution(null)); } else { return new LinkedHashSet<>(0);
try { program.getKRInterface().initialize(uris); } catch (KRInitFailedException e) { reportError(ModuleError.KR_COULDNOT_INITIALIZE, ctx, e.getMessage()); SourceInfo definition = getSourceInfo(ctx.ID()); getProgram().setDefinition(definition); if (!FilenameUtils.getBaseName(definition.getSource()).equals(name)) { reportWarning(ModuleWarning.MODULE_NAME_MISMATCH, ctx.ID());
Set<DatabaseFormula> knowledgeDfNotUsedInKB = this.program.getKRInterface().getUnused(getKnowledge(), new LinkedHashSet<Query>(0)); tempQueries.addAll(getGoals()); Set<DatabaseFormula> unusedKnowledgeOrBeliefs = this.program.getKRInterface().getUnused(tempDbfs, tempQueries); Set<Query> undefinedBeliefQueries = this.program.getKRInterface().getUndefined(tempDbfs, getBeliefQueries()); Set<Query> unachievableGoals = this.program.getKRInterface().getUndefined(tempDbfs, getGoals()); tempDbfs.addAll(getGoalDbfs()); tempQueries = new LinkedHashSet<>(getGoalQueries()); Set<DatabaseFormula> unusedGoals = this.program.getKRInterface().getUnused(tempDbfs, tempQueries); knowledgeDfNotUsed.retainAll(unusedGoals); Set<Query> undefinedGoalQueries = this.program.getKRInterface().getUndefined(tempDbfs, getGoalQueries()); .removeAll(this.program.getKRInterface().getUndefined(getKnowledge(), new LinkedHashSet<Query>(0))); this.firstPass.reportError(ModuleError.KR_BELIEF_QUERIED_NEVER_DEFINED, query.getSourceInfo(), query.toString()); this.firstPass.reportError(ModuleError.KR_GOAL_QUERIED_NEVER_DEFINED, query.getSourceInfo(), query.toString()); this.firstPass.reportWarning(ModuleWarning.KR_GOAL_DOES_NOT_MATCH_BELIEF, query.getSourceInfo(), query.toString());
SwiPrologGoal(GoalBase owner, Update goal) throws MSTDatabaseException { super(owner.getOwner(), goal); try { this.database = (PrologDatabase) owner.getOwner().getOwner().getKRInterface().getDatabase( owner.getOwner().getAgentId() + ":" + owner.getName() + ":" + goal, goal.getAddList(), false); owner.getOwner().createdDatabase(this.database, BASETYPE.GOALBASE); } catch (KRDatabaseException e) { throw new MSTDatabaseException( "could not create a database for '" + goal + "' of '" + owner.getOwner().getOwner() + "'.", e); } }
for (DatabaseFormula unused : kri.getUnused(this.predicateDefinitions, this.predicateQueries)) { if (had.add(unused.getSignature())) { this.beliefsUnused.add(unused);
/** * * @param owner * the owner (MentalState). * @param forAgent * the agent owning this database * @param type * the type of this database. If type is BASETYPE.KNOWLEDGEBASE, * this database will be assumed static * @param dbfs * the initial database formulas. If null, the initial database * is set empty. * @throws MSTDatabaseException */ protected SwiPrologMentalBase(MentalState owner, AgentId forAgent, BASETYPE type, List<DatabaseFormula> dbfs) throws MSTDatabaseException { super(owner, forAgent, type); try { this.database = (PrologDatabase) owner.getOwner().getKRInterface().getDatabase( owner.getAgentId() + ":" + forAgent + ":" + type, dbfs, type == BASETYPE.KNOWLEDGEBASE); this.owner.createdDatabase(this.database, type); } catch (KRDatabaseException e) { throw new MSTDatabaseException("could not create a database for '" + owner.getOwner() + "'.", e); } }