我正在使用Flask-Ask制作一个alexa技能,它有一个自定义的槽-性别。主要取值为“男”、“女”,对应的同义词有“他”、“她”、“男孩”、“女孩”等。
这项技能只会根据人的性别做出反应。例如:一句“他24岁”应该给“男性”,但给“他”作为回应。
我可以在技能的Json输出中看到正确的值,但是在flask-ask中有比在意图处理程序中编码或解析json响应更简单的内置函数来处理解析吗?
如有任何帮助,将不胜感激
发布于 2018-08-04 02:34:13
我遇到了类似的问题,我用一个小函数解析了JSON:
def resolved_values(request):
"""
Takes the request JSON and converts it into a dictionary of your intent
slot names with the resolved value.
Example usage:
resolved_vals = resolved_values(request)
txt = ""
for key, val in resolved_vals.iteritems():
txt += "\n{}:{}".format(key, val)
:param request: request JSON
:return: {intent_slot_name: resolved_value}
"""
slots = request["intent"]["slots"]
slot_names = slots.keys()
resolved_vals = {}
for slot_name in slot_names:
slot = slots[slot_name]
if "resolutions" in slot:
slot = slot["resolutions"]["resolutionsPerAuthority"][0]
slot_status = slot["status"]["code"]
if slot_status == "ER_SUCCESS_MATCH":
resolved_val = slot["values"][0]["value"]["name"]
resolved_vals[slot_name] = resolved_val
else:
resolved_vals[slot_name] = None
else: # No value found for this slot value
resolved_vals[slot_name] = None
return resolved_valshttps://stackoverflow.com/questions/50349084
复制相似问题