如何在 Alexa 中处理意图中的同义词?

编程入门 行业动态 更新时间:2024-10-04 15:24:21
本文介绍了如何在 Alexa 中处理意图中的同义词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在以下示例中:如果用户说太妃糖,那不应该翻译成糖果吗?我问是因为传递给我的意图的价值是太妃糖".所以不确定我有什么不正确.

In the following example: If the user says toffee, shouldn't that be translated to candy? I ask because the value handed to my intent is 'toffee'. So not sure what I have incorrect.

types":[ { "name":"SHOPPING_LIST", "values":[ { "id":null, "name":{ "value":"candy", "synonyms":[ "toffee" ] } }, { "name":"GetPrice", "samples":[ "Get me the price of {item}", "tell me the price of {item}", ], "slots":[ { "name":"item", "type":"SHOPPING_LIST" } ] }

推荐答案

我们需要在您的后端代码中处理实体解析.更多可以参考这里:developer.amazon/blogs/alexa/post/5de2b24d-d932-4c6f-950d-d09d8ffdf4d4/entity-resolution-and-slot-validation

We need to handle the entity resolution in your backend code. More can be referred here: developer.amazon/blogs/alexa/post/5de2b24d-d932-4c6f-950d-d09d8ffdf4d4/entity-resolution-and-slot-validation

您可以在代码中添加,

this.attributes.item = slotValue(this.event.request.intent.slots.item);

另外,在你的处理函数之外添加这个,

Also, add this outside your handler function,

function slotValue(slot, useId){ let value = slot.value; let resolution = (slot.resolutions && slot.resolutions.resolutionsPerAuthority && slot.resolutions.resolutionsPerAuthority.length > 0) ? slot.resolutions.resolutionsPerAuthority[0] : null; if(resolution && resolution.status.code == 'ER_SUCCESS_MATCH'){ let resolutionValue = resolution.values[0].value; value = resolutionValue.id && useId ? resolutionValue.id : resolutionValue.name; } return value; }

现在当您的用户输入太妃糖时,它会被翻译成糖果.

Now when your user enters toffee, it will be translated to candy.

更多推荐

如何在 Alexa 中处理意图中的同义词?

本文发布于:2023-11-28 03:24:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640768.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:同义词   意图   如何在   Alexa

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!