예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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
예제 #6
0
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
예제 #7
0
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)
예제 #8
0
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)
예제 #9
0
 def assert_unification(self, first, second, expected, theta={}):
     #print(logic.unify(first, second, theta))
     self.assertEqual(logic.unify(first, second, theta), expected)
예제 #10
0
 def assert_unification(self, first, second, expected, theta={}):
     #print(logic.unify(first, second, theta))
     self.assertEqual(logic.unify(first, second, theta), expected)