Aws lambda 在Alexa中如何处理意图中的同义词?
在以下示例中: 如果用户说太妃糖,不应该翻译成糖果吗?我这样问是因为我的意图是“太妃糖”。所以不确定我有什么不正确的Aws lambda 在Alexa中如何处理意图中的同义词?,aws-lambda,alexa,alexa-skills-kit,alexa-skill,alexa-voice-service,Aws Lambda,Alexa,Alexa Skills Kit,Alexa Skill,Alexa Voice Service,在以下示例中: 如果用户说太妃糖,不应该翻译成糖果吗?我这样问是因为我的意图是“太妃糖”。所以不确定我有什么不正确的 types":[ { "name":"SHOPPING_LIST", "values":[ { "id":null, "name":{ "value":"candy", "synonyms":[
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"
}
]
}
我们需要在您的后端代码中处理实体解析。 有关详情,请参阅: 您可以在代码中添加
this.attributes.item = slotValue(this.event.request.intent.slots.item);
另外,将其添加到处理程序函数之外
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;
}
现在,当您的用户输入太妃糖时,它将被转换为candy。一般的响应JSON结构如下,以便在一行中提取它 来源= intent.slots.source.resolutions.resolutionsPerAuthority[0]。值[0]。值.name
希望这将是简单而有用的。感谢您提供的出色功能,但我发现它在某种程度上不适合我们。这是真的。为了弄清楚是否有什么内在的东西,我把脑袋弄得一团糟。不幸的是,现在还没有。@Caltor实际上响应是一个JSON,所以要提取,您只需按照树进行操作,请参阅下面我的答案,直接提取,而不向任何函数传递任何内容。如果不存在,这将抛出错误。这就是@DreamSaver使用if语句查看它是否存在的原因。另外,his是一个函数,因此在整个技能中可以重用。
"request": {
"type": "IntentRequest",
"requestId": "amzn1.ech****************************************************************************************",
"timestamp": "2019-03-13T08:34:46Z",
"locale": "en-US",
"intent": {
"name": "STMDStreamStartIntent",
"confirmationStatus": "NONE",
"slots": {
"source": {
"name": "source",
"value": "source 1",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.e************************************************",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "source1",
"id": "SOURCE_ONE"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
}
}