Beispiel #1
0
    def postprocess(self, t):
        if t.root in ['γ', 'E', 'E0', 'E1', "E1'", 'A', 'T', 'T1'] and len(
                t.subtrees) == 1:
            return self.postprocess(t.subtrees[0])
        elif t.root in ['E0', 'T1'] and t.subtrees[0].root == '(':
            return self.postprocess(t.subtrees[1])
        elif t.root == r'\.':
            args = self.postprocess(t.subtrees[1]).split()
            t = reduce(lambda t, a: Tree('\\', [a, t]), reversed(args),
                       t.subtrees[3])
        elif t.root == "@'":
            t = Tree('@', t.subtrees)
        elif t.root in ['L', 'A0']:
            t = Tree('.', t.split())
        elif t.root == 'A1':
            r = [self.postprocess(s) for s in t.subtrees]
            if r[0].root == 'id': return Tree('.', r)
            elif r[0].root == '(':  #  ( L:T ) A1
                return Tree('.', r[1].subtrees + r[3:])
        elif t.root == 'L:T':
            r = [self.postprocess(s) for s in t.subtrees]
            l, ty = r[0], r[2]
            return Tree('.', [Tree(r[1].root, [a, ty]) for a in l.split()])
        elif t.root in ['id:T', 'T>']:
            t = Tree(t.subtrees[1].root, [t.subtrees[0], t.subtrees[2]])

        return Tree(t.root, [self.postprocess(s) for s in t.subtrees])
Beispiel #2
0
    def postprocess(self, t):
        if t.root in ['γ', 'E', 'E0', 'E1', "E1'"] and len(t.subtrees) == 1:
            return self.postprocess(t.subtrees[0])
        elif t.root == 'E0' and t.subtrees[0].root == '(':
            return self.postprocess(t.subtrees[1])
        elif t.root == r'\.':
            args = t.subtrees[1].split()
            t = reduce(lambda t, a: Tree('\\', [a, t]), reversed(args),
                       t.subtrees[3])
        elif t.root == "@'":
            t = Tree('@', t.subtrees)
        elif t.root == 'L':
            t = Tree('.', t.split())

        return Tree(t.root, [self.postprocess(s) for s in t.subtrees])