combination.addBinding(var, get(var)); } else { combination.addBinding(var, term); for (Var var : substitution.getVariables()) { if (get(var) == null) { Term term = substitution.get(var).applySubst(substitution); if (!var.equals(term)) { combination.addBinding(var, term); Substitution mgu = substitution.get(var).mgu(get(var)); if (mgu != null) { combination = combination.combine(mgu); } else { // fail: two different bindings for one and the same
@Override public default Substitution unify(Term x, Substitution s) { if (s == null) { return null; } else if (equals(x)) { return s; } PrologTerm st = (PrologTerm) s.get(this); if (st != null) { return st.unify(x, s); } PrologTerm sx = (x instanceof Var) ? (PrologTerm) s.get((Var) x) : null; if (sx != null) { return unify(sx, s); } else if (x.getFreeVar().contains(this)) { return null; } else { s.addBinding(this, x); return s; } } }
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; } }
@Override public ListallDoRule applySubst(Substitution substitution) { // Make sure to not instantiate the variable assigned to by this rule. // TODO: can we delegate this to check during compile time? Substitution safesubstitution = substitution.clone(); safesubstitution.remove(getVariable()); return new ListallDoRule((getCondition() == null) ? null : getCondition().applySubst(substitution), getVariable(), (getAction() == null) ? null : getAction().applySubst(safesubstitution), getSourceInfo()); }
for (Substitution subst : result) { try { subst.addBinding(var, translator.convert(this.forAgent)); } catch (MSTTranslationException e) { throw new MSTQueryException("failed to bind selector variable to agent name", e);
@Override public Term applySubst(Substitution s) { Term value = (s == null) ? null : s.get(this); return (value == null) ? this : value; }
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; } }
tempResult.add(currentSubstitution.combine(answer));
generator); for (Substitution tempSubst : tempResult) { currentResults.add(subst.combine(tempSubst));