def get_predicate_arguments(atomspace, predicate_name): """ Finds the unique EvaluationLink for a predicate and returns its list of arguments. (Adapted from Alex's PLNUnitTester class) :param atomspace: the atomspace where the predicate should be looked for :param predicate_name: the name of the predicate :return: a list of the predicate arguments """ chainer = Chainer(atomspace) var = chainer.new_variable() predicate = chainer.atomspace.add_node(types.PredicateNode, predicate_name) template = chainer.link(types.EvaluationLink, [predicate, var]) queries = chainer.lookup_atoms(template, "") # The template needs to be removed from the results queries.remove(template) if len(queries) != 1: if predicate_name == "undesired_outputs": return None else: raise ValueError("Predicate {0} must have 1 EvaluationLink" .format(predicate_name)) return queries[0].out[1].out
def get_predicate_arguments(atomspace, predicate_name): """ Finds the unique EvaluationLink for a predicate and returns its list of arguments. (Adapted from Alex's PLNUnitTester class) :param atomspace: the atomspace where the predicate should be looked for :param predicate_name: the name of the predicate :return: a list of the predicate arguments """ chainer = Chainer(atomspace) var = chainer.new_variable() predicate = chainer.atomspace.add_node(types.PredicateNode, predicate_name) template = chainer.link(types.EvaluationLink, [predicate, var]) queries = chainer.lookup_atoms(template, "") # The template needs to be removed from the results queries.remove(template) if len(queries) != 1: if predicate_name == "undesired_outputs": return None else: raise ValueError("Predicate {0} must have 1 EvaluationLink".format( predicate_name)) return queries[0].out[1].out