Ejemplo n.º 1
0
def find_satisfying_assignments(kb,
                                conds,
                                variable_sort_fn=None,
                                verbose=False,
                                max_assignment_count=2,
                                type_to_parent_types=None,
                                allow_redundant_variables=True,
                                constants=None,
                                mode="csp",
                                init_assignments=None):
    if mode == "csp":
        return ProofSearchTree(
            kb,
            allow_redundant_variables=allow_redundant_variables,
            type_to_parent_types=type_to_parent_types,
            constants=constants,
            initial_assignments=init_assignments,
        ).prove(list(conds),
                max_assignment_count=max_assignment_count,
                variable_sort_fn=variable_sort_fn,
                verbose=verbose)
    assert mode == "prolog"
    assert all(len(v) == 1 for v in type_to_parent_types.values()), \
        "TODO: implement support for hierarchical types in prolog inference"
    prolog_interface = PrologInterface(
        kb,
        conds,
        max_assignment_count=max_assignment_count,
        allow_redundant_variables=allow_redundant_variables,
        constants=constants)
    return prolog_interface.run()
Ejemplo n.º 2
0
def check_goal(state, goal):
    if isinstance(goal, Literal):
        if goal.is_negative and goal.positive in state.literals:
            return False
        if not goal.is_negative and goal not in state.literals:
            return False
        return True
    if isinstance(goal, LiteralConjunction):
        return all(check_goal(state, lit) for lit in goal.literals)
    prolog_interface = PrologInterface(state.literals, goal,
        max_assignment_count=2,
        allow_redundant_variables=True)
    assignments = prolog_interface.run()
    return len(assignments) > 0