def __fetch_implications(kb, query): implications = [] for implication in kb: subst = unify(query, implication.conclusion) if subst != problem.FAILURE: implication.standardize() implications.append(implication) return implications
def is_fo_disjunction_tautology(disjunction): for symbol in disjunction: negation = LogicOperator.Negation + symbol for symbol2 in disjunction: theta = unify(negation, symbol2) if theta is not FAILURE: return True return False
def __backward_chaining_or(kb, query, theta): for implication in __fetch_implications(kb, query): premises, conclusion = implication.premises, implication.conclusion subst = __backward_chaining_and(kb, premises, unify(query, conclusion, theta)) if subst is not problem.FAILURE: return subst return problem.FAILURE
def __resolve_single_sided(c1, c2, resolvents, clause_mapping): for symbol1 in c1: negation = LogicOperator.Negation + symbol1 for symbol2 in c2: for th in clause_mapping.get_unified_bindings(c1, c2): theta = unify(negation, symbol2, th) if theta is not problem.FAILURE: result = c1.union(c2).difference({symbol1, symbol2}) resolvent = __standardize_resolvent(result, theta) resolvents.append(resolvent) clause_mapping.container[resolvent].append(theta)
def assert_unification(self, first, second, expected, theta={}): #print(logic.unify(first, second, theta)) self.assertEqual(logic.unify(first, second, theta), expected)