Skip to content

Instantly share code, notes, and snippets.

@zaoldyeck
Last active October 18, 2018 09:07
Show Gist options
  • Save zaoldyeck/584124a0865e8e6d5a5200028580813c to your computer and use it in GitHub Desktop.
Save zaoldyeck/584124a0865e8e6d5a5200028580813c to your computer and use it in GitHub Desktop.
+from api.kkbox import KKBOX
class Olami:
def intent_detection(self, nli_obj):
+ def handle_music_kkbox_type(semantic):
+ music_type = semantic['modifier'][0].split('_')[2]
+ slots = semantic['slots']
+ kkbox = KKBOX()
+
+ def get_slot_value_by_key(key):
+ return next(filter(lambda el: el['name'] == key, slots))['value']
+
+ key = 'keyword' if music_type == 'playlist' else (music_type + '_name')
+ return kkbox.search(music_type, get_slot_value_by_key(key))
type = nli_obj['type']
desc = nli_obj['desc_obj']
data = nli_obj.get('data_obj', [])
if type == 'kkbox':
id = data[0]['id']
return ('https://widget.kkbox.com/v1/?type=song&id=' + id) if len(data) > 0 else desc['result']
elif type == 'baike':
return data[0]['description']
elif type == 'joke':
return data[0]['content']
elif type == 'news':
return data[0]['detail']
elif type == 'cooking':
return data[0]['content']
elif type == 'selection':
return handle_selection_type(desc['type'])
elif type == 'ds':
return desc['result'] + '\n請用 /help 指令看看我能怎麼幫助您'
+ elif type == 'music_kkbox':
+ return handle_music_kkbox_type(nli_obj['semantic'][0])
else:
return desc['result']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment