@@ -179,6 +179,15 @@ def retrieve_workspace(skill_id, conversation, export_flag=True):
179
179
return ws_json .get_result ()
180
180
181
181
182
+ def _get_intent_name_from_action_condition (condition : dict ):
183
+ if "intent" in condition and condition ["intent" ] is not None :
184
+ return condition ["intent" ]
185
+ for v in condition .values ():
186
+ if isinstance (v , list ):
187
+ for cond in v :
188
+ return _get_intent_name_from_action_condition (cond )
189
+
190
+
182
191
def parse_workspace_json (workspace_json ):
183
192
"""
184
193
Parse workspace json and returns list of utterances, list of intents, and list of entities, and intent to action title mapping
@@ -202,13 +211,17 @@ def parse_workspace_json(workspace_json):
202
211
203
212
else :
204
213
# intent name to action title mapping for readability
205
- raw_intent_name_to_action_title_mapping = {
206
- action [ "condition " ]["intent " ]: action [ "title" ]
207
- for action in workspace_json [ "workspace" ][ "actions" ]
208
- if action . get ( "condition" , {}). get ( "intent" )
209
- }
214
+ raw_intent_name_to_action_title_mapping = {}
215
+ for action in workspace_json [ "workspace " ]["actions " ]:
216
+ possible_intent = _get_intent_name_from_action_condition ( action . get ( "condition" , {}))
217
+ if possible_intent :
218
+ raw_intent_name_to_action_title_mapping [ possible_intent ] = action [ "title" ]
210
219
for intent in workspace_json ["workspace" ]["intents" ]:
211
- action_title = raw_intent_name_to_action_title_mapping [intent ["intent" ]]
220
+ intent_name = intent ["intent" ]
221
+ action_title = raw_intent_name_to_action_title_mapping .get (intent_name )
222
+ if action_title is None :
223
+ raw_intent_name_to_action_title_mapping [intent_name ] = intent_name
224
+ action_title = intent_name
212
225
for example in intent ["examples" ]:
213
226
utterances .append (example ["text" ])
214
227
intents .append (action_title )
0 commit comments