Beispiel #1
0
def resolution_prover(knowledge_base, query, max_clause_len, is_complete):
    negated_query = "{0}({1})".format(LogicOperator.Negation, query)
    not_query_cnf = parse_cnf(negated_query)
    clauses = not_query_cnf + knowledge_base
    new_inferrences = set()
    already_resolved = set()
    clause_theta_mapping = ClauseBindingMapper()

    clauses2 = parse_cnf(query) + knowledge_base
    new_inferrences2 = set()
    already_resolved2 = set()
    clause_theta_mapping2 = ClauseBindingMapper()

    empty_set = frozenset()
    support = not_query_cnf
    support2 = parse_cnf(query)

    while True:
        result = __resolution_step(new_inferrences, already_resolved, clauses,
                                   max_clause_len, clause_theta_mapping)
        if result is not None:
            if result[0]:
                return {
                    var: value
                    for var, value in result[1].items()
                    if var in find_variables_expression(query)
                }

            return problem.FAILURE

        if is_complete:
            result = __resolution_step(new_inferrences2, already_resolved2,
                                       clauses2, max_clause_len,
                                       clause_theta_mapping2)
            if result is not None:
                if result[0]:
                    return {
                        var: value
                        for var, value in result[1].items()
                        if var in find_variables_expression(query)
                    }
                return problem.FAILURE
Beispiel #2
0
def resolution_prover(knowledge_base, query, max_clause_len, is_complete):
    negated_query = "{0}({1})".format(LogicOperator.Negation, query)
    not_query_cnf = parse_cnf(negated_query)
    clauses = not_query_cnf + knowledge_base
    new_inferrences = set()
    already_resolved = set()
    clause_theta_mapping = ClauseBindingMapper()

    clauses2 = parse_cnf(query) + knowledge_base
    new_inferrences2 = set()
    already_resolved2 = set()
    clause_theta_mapping2 = ClauseBindingMapper()

    empty_set = frozenset()
    support = not_query_cnf
    support2 = parse_cnf(query)

    while True:
        result = __resolution_step(new_inferrences, already_resolved,
                                   clauses, max_clause_len,
                                   clause_theta_mapping)
        if result is not None:
            if result[0]:
                return {var: value for var, value in result[1].items()
                        if var in find_variables_expression(query)}

            return problem.FAILURE

        if is_complete:
            result = __resolution_step(new_inferrences2, already_resolved2,
                                       clauses2, max_clause_len,
                                       clause_theta_mapping2)
            if result is not None:
                if result[0]:
                    return {var: value for var, value in result[1].items()
                            if var in find_variables_expression(query)}
                return problem.FAILURE
Beispiel #3
0
def resolution_prover(knowledge_base, query, max_clause_len, information_rich):
    negated_query = "{0}({1})".format(LogicOperator.Negation, query)
    not_query_cnf = parse_cnf(negated_query)
    clauses = not_query_cnf + knowledge_base
    new_inferrences = set()
    already_resolved = set()

    clauses2 = parse_cnf(query) + knowledge_base
    new_inferrences2 = set()
    already_resolved2 = set()

    empty_set = frozenset()

    while True:
        result = __resolution_step(new_inferrences, already_resolved, clauses,
                                   max_clause_len)
        if result is not None:
            return result

        if information_rich:
            result = __resolution_step(new_inferrences2, already_resolved2,
                                       clauses2, max_clause_len)
            if result is not None:
                return not result
Beispiel #4
0
def resolution_prover(knowledge_base, query, max_clause_len, information_rich):
    negated_query = "{0}({1})".format(LogicOperator.Negation, query)
    not_query_cnf = parse_cnf(negated_query)
    clauses = not_query_cnf + knowledge_base
    new_inferrences = set()
    already_resolved = set()

    clauses2 = parse_cnf(query) + knowledge_base
    new_inferrences2 = set()
    already_resolved2 = set()

    empty_set = frozenset()

    while True:
        result = __resolution_step(new_inferrences, already_resolved,
                                   clauses, max_clause_len)
        if result is not None:
            return result

        if information_rich:
            result = __resolution_step(new_inferrences2, already_resolved2,
                                       clauses2, max_clause_len)
            if result is not None:
                return not result
Beispiel #5
0
def __parser(sentence):
    return parse_cnf(standardize_variables(sentence)[0])
Beispiel #6
0
def __parser(sentence):
    return parse_cnf(standardize_variables(sentence)[0])