forked from pcyin/NL2code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.py
50 lines (41 loc) · 1.49 KB
/
parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import ast
import re
import sys, inspect
from StringIO import StringIO
import astor
from collections import OrderedDict
from tokenize import generate_tokens, tokenize
import token as tk
from nn.utils.io_utils import deserialize_from_file, serialize_to_file
from astnode import *
if __name__ == '__main__':
# node = ast.parse('''
# # for i in range(1, 100):
# # sum = sum + i
# #
# # sorted(arr, reverse=True)
# # sorted(my_dict, key=lambda x: my_dict[x], reverse=True)
# # m = dict ( zip ( new_keys , keys ) )
# # for f in sorted ( os . listdir ( self . path ) ) :
# # pass
# for f in sorted ( os . listdir ( self . path ) ) : pass
# ''')
# print ast.dump(node, annotate_fields=False)
# print get_tree_str_repr(node)
# print parse('sorted(my_dict, key=lambda x: my_dict[x], reverse=True)')
# print parse('global _standard_context_processors')
# parse_django('/Users/yinpengcheng/Research/SemanticParsing/CodeGeneration/en-django/all.code')
# code = 'sum = True'
# print parse_tree
# ast_tree = tree_to_ast(parse_tree)
# # # # #
# import astor
# print astor.to_source(ast_tree)
from dataset import DataSet, Vocab, DataEntry, Action
# train_data, dev_data, test_data = deserialize_from_file('django.cleaned.dataset.bin')
# cand_list = deserialize_from_file('cand_hyps.18771.bin')
# hyp_tree = cand_list[3].tree
#
# ast_tree = decode_tree_to_ast(hyp_tree)
# print astor.to_source(ast_tree)
pass