Exemple #1
0
class GKPrologVisitorAtoms(GKPrologVisitorAlgebraicWeight):
    def __init__(self):
        self.pred2semiring = {}
        self.bogus_atom_manager = BogusAtomManager(self.pred2semiring)

    def Atom(self, *args, **kwargs):
        atom = Atom(*args, **kwargs)
        if atom.predicate not in self.pred2semiring and atom.predicate not in BUILTIN_PREDICATES:
            warnings.warn("undeclared {}".format(str(atom.predicate)))
        return atom

    def create_bogus_atom(self, predicate):
        return self.bogus_atom_manager.create_bogus_atom(predicate)

    # Visit a parse tree produced by GKPrologParser#AtomZero.
    def visitAtomZero(self, ctx):
        functor = self.visit(ctx.constant())
        args = ()
        arity = 0
        predicate = Predicate(functor, arity)
        return self.Atom(predicate, *args)

    # Visit a parse tree produced by GKPrologParser#AtomNonZero.
    def visitAtomNonZero(self, ctx):
        functor = self.visit(ctx.constant())
        args = self.visit(ctx.term_list())
        arity = len(args)
        predicate = Predicate(functor, arity)
        return self.Atom(predicate, *args)

    # Visit a parse tree produced by GKPrologParser#AtomInList.
    def visitAtomInList(self, ctx):
        return (self.visit(ctx.atom()),)

    # Visit a parse tree produced by GKPrologParser#AtomList.
    def visitAtomList(self, ctx):
        return (self.visit(ctx.atom()),) + self.visit(ctx.atom_list())

    # Visit a parse tree produced by GKPrologParser#SimpleBodyAtom.
    def visitSimpleBodyAtom(self, ctx):
        return self.visit(ctx.atom())

    # Visit a parse tree produced by GKPrologParser#DecoratedBodyAtom.
    def visitDecoratedBodyAtom(self, ctx):
        metafunction_name = self.visit(ctx.constant())
        metafunction_args = self.visit(ctx.body_atom_list())
        return Metafunction(metafunction_name, metafunction_args)

    # Visit a parse tree produced by GKPrologParser#BodyAtomInList.
    def visitBodyAtomInList(self, ctx):
        return (self.visit(ctx.body_atom()),)

    # Visit a parse tree produced by GKPrologParser#BodyAtomList.
    def visitBodyAtomList(self, ctx):
        return (self.visit(ctx.body_atom()),) + self.visit(ctx.body_atom_list())
Exemple #2
0
 def __init__(self):
     self.pred2semiring = {}
     self.bogus_atom_manager = BogusAtomManager(self.pred2semiring)