-
Notifications
You must be signed in to change notification settings - Fork 2
/
actions.py
165 lines (164 loc) · 6.37 KB
/
actions.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
'''
Written by Debojit Kaushik (Timestamp)
'''
import os
import sys
import traceback
class Action:
@staticmethod
def get_action(intent_data):
try:
action_dic = None
intents = [
"add_function",
"add_if_else",
"add_main",
"add_while",
"goto",
"call_function",
"add_variables",
"add_class",
"add_try_catch",
"save_file",
"run_file",
"add_newline",
"add_breakpoint"
]
intent = intent_data["topScoringIntent"]["intent"]
print(intent)
if intent in intents:
if intent == "add_function":
action_dic = {
"status": "Function Creation Returned",
"action": "add_fun",
"data": {
"func_name": [i["entity"] for i in intent_data["entities"] if i["type"] == "function_name"][0],
"args": [i["entity"] for i in intent_data["entities"] if i["type"] == "argument"]
}
}
elif intent == "add_if_else":
action_dic = {
"status": "If-else Block Created",
"action": "add_if_else",
"data": {
"args": []
}
}
elif intent == "add_main":
action_dic = {
"status": "Main Function Created",
"action": "add_main",
"data": {}
}
elif intent == "add_while":
action_dic = {
"status": "While statement added.",
"action": "add_while",
"data": {
"args": intent_data["query"]
}
}
elif intent == "goto":
action_dic = {
"status": "Go to line/function called.",
"action": "goto",
"data": {
"args": intent_data["entities"][0]["resolution"]["value"],
"type": intent_data["entities"][0]["type"]
}
}
elif intent == "call_function":
action_dic = {
"status": "Function called.",
"action": "call_function",
"data": {
"args": [{"entity": item["entity"], "type": item["type"]} for item in intent_data["entities"]]
}
}
elif intent == "add_variables":
action_dic = {
"status": "Variable added.",
"action": "add_variable",
"data": {
"args": [{"entity": item['entity'], "type": item['type']} for item in intent_data['entities']]
}
}
#Here
elif intent == "add_breakpoint":
action_dic = {
"status": "Breakpoint added.",
"action": "add_breakpoint",
"data": {
"args": []
}
}
elif intent == "add_class":
action_dic = {
"status": "class added/created.",
"action": "add_class",
"data": {
"args": [{"entity": item['entity'], "type": item['type']} for item in intent_data['entities']]
}
}
elif intent == "add_newline":
action_dic = {
"status": "NewLine inserted.",
"action": "add_newline",
"data": {
"args": intent_data["entities"][0]["resolution"]["value"],
"type": intent_data["entities"][0]["type"]
}
}
elif intent == "add_try_catch":
action_dic = {
"status": "Exception Handling block added.",
"action": "add_try_catch",
"data": {
"args": []
}
}
elif intent == "delete_line":
action_dic = {
"status": "Line Removed",
"action": "delete_line",
"data": {
"args": []
}
}
elif intent == "run_file":
action_dic = {
"status": "Running script",
"action": "run_file",
"data": {
"args": []
}
}
elif intent == "save_file":
action_dic = {
"status": "Saved script.",
"action": "save_file",
"data": {
"args": []
}
}
elif intent == "undo_changes":
action_dic = {
"status": "Changes reverted back (Undo).",
"action": "undo_changes",
"data": {
"args": []
}
}
else:
action_dic = {
"status": "Invalid query"
}
print(action_dic)
return action_dic
else:
action_dic = {
"status": "Invalid query"
}
return action_dic
except Exception:
print(traceback.format_exc())