/** * @see Name * @see Inequality * <p>Inverse of the Unifying Method, receives two WellFormedNames and tries to find a list of * Substitutions that will make both names syntatically different. * @param n1 - The first Name * @param n2 - The second Name * @return A list of substitutions (Inequalities) if the names can be made different, otherwise * returns null */ public static boolean Disunify(Name n1, Name n2, ArrayList<Substitution> bindings) { Name aux1; Name aux2; ArrayList<Substitution> bindAux; if (n1 == null || n2 == null) return false; // parto do principio que a lista de bindings está consistente aux1 = (Name) n1.clone(); aux2 = (Name) n2.clone(); aux1.makeGround(bindings); aux2.makeGround(bindings); if (aux1.isGrounded() && aux2.isGrounded()) { return !aux1.equals(aux2); } bindAux = FindSubst(aux1, aux2); if (bindAux != null) { for (Substitution s : bindAux) { bindings.add(new Inequality(s)); } } return true; }
/** * @see Name * @see Substitution * <p>Unifying Method similar to Unify but with an important difference. If one of the * unifying names is smaller or bigger than the other, this method considers that the names * can still be partially unifyable. The regular Unify method will always return false in such * situations. * @param n1 - The first Name * @param n2 - The second Name * @param binding - Place an empty Substitution List here * @return True if the names are unifyable, even if they do not have the same size one can be * unified with the initial partof the other, in this case the bindings list will contain the * found Substitutions, otherwise it will be empty */ public static boolean PartialUnify(Name n1, Name n2, ArrayList<Substitution> bindings) { Name aux1; Name aux2; ArrayList<Substitution> bindAux; if (n1 == null || n2 == null) return false; // parto do principio que a lista de bindings está consistente aux1 = (Name) n1.clone(); aux2 = (Name) n2.clone(); aux1.makeGround(bindings); aux2.makeGround(bindings); if (aux1.isGrounded() && aux2.isGrounded()) { return aux1.toString().startsWith(aux2.toString()) || aux2.toString().startsWith(aux1.toString()); } bindAux = FindPartialSubst(aux1, aux2); if (bindAux == null) return false; bindings.addAll(bindAux); return true; }