def unify(x, y, theta): if theta is False: return False if (x == y): return theta if (Fact.is_variable(x)): return unifyVar(x, y, theta) elif (Fact.is_variable(y)): return unifyVar(y, x, theta) elif (Fact.is_fact(x) and Fact.is_fact(y)): return unify(x.get_args(), y.get_args(), unify(x.get_op(), y.get_op(), theta)) elif (Fact.is_list(x) and Fact.is_list(y)): return unify(x[1:], y[1:], unify(x[0], y[0], theta)) return False
def resolution_search(kb, goal): consts = kb.getAllConsts() args = goal.get_args() var_loc = [] for i in range(len(args)): if Fact.is_variable(args[i]): var_loc.append(i) if len(var_loc) == 0: return resolution(kb, goal) theta = [list() for i in range(len(var_loc))] newGoal = goal.copy() if set_variable(var_loc, 0, kb, newGoal, consts, theta) is not False: string = str() for i in range(len(theta[0])): line = "{" for j in range(len(var_loc)): line += "{} = {}, ".format(goal.get_args()[var_loc[j]], theta[j][i]) string += line.rstrip(", ") + "}; " return string.rstrip("; ") return False