コード例 #1
0
        def body(toks):
            # HACK
            tag = toks.next()

            head_index = None
            if toks.peek() == '<' and (not tag == 'PU'):
                toks.next()
                head_index = int(toks.next())
                shift_and_check( '>', toks )

            category = None
            if toks.peek() == '{':
                toks.next()
                category = parse_category(toks.next())
                shift_and_check( '}', toks )

            kids = []

            lex = None
            while toks.peek() != ')':
                if toks.peek() == '(':
                    kids.append( self.read_deriv(toks) )
                else:
                    lex = toks.next()

            if (not kids) and lex:
                return A.Leaf(tag, lex, category, parent)
            else:
                ret = A.Node(tag, kids, category, parent, head_index)
                for kid in ret: kid.parent = ret
                return ret
コード例 #2
0
ファイル: parse.py プロジェクト: Oneplus/cnccgbank
    def read_internal_node(self, toks, parent):
        shift_and_check( 'T', toks )

        cat_string, head_index, child_count = \
                toks.next(), toks.next(), toks.next()
        cat = parse_category(cat_string)
        #head_index = int(head_index)

        return self.node_factory.node_class(cat, head_index, child_count, parent)
コード例 #3
0
ファイル: parse.py プロジェクト: Oneplus/cnccgbank
    def read_leaf_node(self, toks, parent=None):
        shift_and_check( 'L', toks )

        cat_string, pos1, pos2, lex, catfix = \
                toks.next(), toks.next(), \
                toks.next(), toks.next(), toks.next()
        cat = parse_category(cat_string)

        return self.node_factory.leaf_class(cat, pos1, pos2, lex, catfix, parent)
コード例 #4
0
    def read_internal_node(self, toks, parent):
        shift_and_check('T', toks)

        cat_string, head_index, child_count = \
                toks.next(), toks.next(), toks.next()
        cat = parse_category(cat_string)
        #head_index = int(head_index)

        return self.node_factory.node_class(cat, head_index, child_count,
                                            parent)
コード例 #5
0
    def read_leaf_node(self, toks, parent=None):
        shift_and_check('L', toks)

        cat_string, pos1, pos2, lex, catfix = \
                toks.next(), toks.next(), \
                toks.next(), toks.next(), toks.next()
        cat = parse_category(cat_string)

        return self.node_factory.leaf_class(cat, pos1, pos2, lex, catfix,
                                            parent)
コード例 #6
0
    def read_paren(self, toks, parent=None):
        shift_and_check('(', toks)
        shift_and_check('<', toks)

        node_type = toks.peek()
        if node_type == 'T':
            result = self.read_internal_node(toks, parent)
            shift_and_check('>', toks)

            lch = self.read_paren(toks, result)
            rch = None
            if toks.peek() == '(': rch = self.read_paren(toks, result)

            result.lch, result.rch = lch, rch
        elif node_type == 'L':
            result = self.read_leaf_node(toks, parent)
            shift_and_check('>', toks)
        else:
            raise CCGbankParseException, \
                    "Node type (T, L) expected here."

        shift_and_check(')', toks)

        return result
コード例 #7
0
ファイル: parse.py プロジェクト: Oneplus/cnccgbank
    def read_paren(self, toks, parent=None):
        shift_and_check( '(', toks )
        shift_and_check( '<', toks )

        node_type = toks.peek()
        if node_type == 'T':
            result = self.read_internal_node(toks, parent)
            shift_and_check( '>', toks )

            lch = self.read_paren(toks, result)
            rch = None
            if toks.peek() == '(': rch = self.read_paren(toks, result)

            result.lch, result.rch = lch, rch
        elif node_type == 'L':
            result = self.read_leaf_node(toks, parent)
            shift_and_check( '>', toks )
        else:
            raise CCGbankParseException, \
                    "Node type (T, L) expected here."

        shift_and_check( ')', toks )

        return result