コード例 #1
0
 def trans2seq(r):
     blocks = []
     func(r, blocks)
     tree = []
     for b in blocks:
         btree = tree_to_index(b)
         tree.append(btree)
     return tree
コード例 #2
0
        def trans2seq(code_xml):
            def tree_to_index(node):
                token = node.tag
                result = [
                    vocab_code[token].index
                    if token in vocab_code else identifier_max
                ]
                children = node.getchildren()
                for child in children:
                    result.append(tree_to_index(child))
                return result

            root = ET.fromstring(code_xml)
            blocks = []
            func(root, blocks)
            tree = []
            for b in blocks:
                btree = tree_to_index(b)
                tree.append(btree)
            return tree
コード例 #3
0
 def trans_to_sequences(ast):
     sequence = []
     func(ast, sequence)
     #print(sequence)
     return sequence