Ejemplo n.º 1
0
def instantiate(statement, bindings):
    """Generate Statement from given statement and bindings. Constructed statement
        has bound values for variables if they exist in bindings.

    Args:
        statement (Statement): statement to generate new statement from
        bindings (Bindings): bindings to substitute into statement
    """
    def handle_term(term):
        if is_var(term):
            bound_value = bindings.bound_to(term.term)
            return lc.Term(bound_value) if bound_value else term
        else:
            return term

    new_terms = [handle_term(t) for t in statement.terms]
    return lc.Statement([statement.predicate] + new_terms)
def instantiate(statement, bindings):
    """Generate Statement from given statement and bindings. Constructed statement
        has bound values for variables if they exist in bindings.

    Args:
        statement (Statement): statement to generate new statement from
        bindings (Bindings): bindings to substitute into statement
    """

    # 这个是定义一个部分的,如果,是term的话,我们就返回什么的,否则,就返回什么的,然后又是一个弄完的
    # 不懂的地方是在太多了, 实例化一个东西的,bound, 这里是递归,自己调用自己, 这个函数是很难写的,
    # 我赌,一定会用到这个函数的,

    def handle_term(term):
        if is_var(term):
            bound_value = bindings.bound_to(term.term)
            return lc.Term(bound_value) if bound_value else term
        else:
            return term

    new_terms = [handle_term(t) for t in statement.terms]
    return lc.Statement([statement.predicate] + new_terms)