Ejemplo n.º 1
0
    def new_literals(self, clause):
        """Generates new literals based on known predicate symbols.
        Generated literal must share atleast one variable with clause"""
        share_vars = variables(clause[0])
        for l in clause[1]:
            share_vars.update(variables(l))

        for pred, arity in self.pred_syms:
            new_vars = {standardize_variables(expr('x')) for _ in range(arity - 1)}
            for args in product(share_vars.union(new_vars), repeat=arity):
                if any(var in share_vars for var in args):
                    yield Expr(pred, *[var for var in args])
Ejemplo n.º 2
0
 def new_literals(self, clause):
     """Generate new literals based on known predicate symbols.
     Generated literal must share at least one variable with clause"""
     share_vars = variables(clause[0])
     for l in clause[1]:
         share_vars.update(variables(l))
     for pred, arity in self.pred_syms:
         new_vars = {standardize_variables(expr('x')) for _ in range(arity - 1)}
         for args in product(share_vars.union(new_vars), repeat=arity):
             if any(var in share_vars for var in args):
                 # make sure we don't return an existing rule
                 if not Expr(pred, args) in clause[1]:
                     yield Expr(pred, *[var for var in args])
Ejemplo n.º 3
0
    def ask(self, q):
        e = expr(q)
        vars = variables(e)
        ans = fol_bc_ask(self, [e])
        res = []
        for a in ans:
            res.append(dict([(x, v) for (x, v) in a.items() if x in vars]))
        res.sort(key=str)

        if res == []:
            return False
        for r in res:
            if r != {}:
                return res
        return True  # res is a list of empty dicts
Ejemplo n.º 4
0
    def ask(self, q):
        e = expr(q)
        vars = variables(e)
        ans = fol_bc_ask(self, [e])
        res = []
        for a in ans:
            res.append(dict([(x, v) for (x, v) in a.items() if x in vars]))
        res.sort(key=str)

        if res == []:
            return False
        for r in res:
            if r != {}:
                return res
        return True  # res is a list of empty dicts