def trans2seq(r): blocks = [] func(r, blocks) tree = [] for b in blocks: btree = tree_to_index(b) tree.append(btree) return tree
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
def trans_to_sequences(ast): sequence = [] func(ast, sequence) #print(sequence) return sequence