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

问题描述 投票:3回答:2

在以下示例中:如果用户说太妃糖,那不应该转换为糖果吗?我问,因为我的意图的价值是“太妃糖”。所以不确定我的错误。

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"
               }
            ]
         }
aws-lambda alexa alexa-skills-kit alexa-skill alexa-voice-service
2个回答
5
投票

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

在您的代码中,您可以添加,

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;
}

现在,当您的用户输入太妃糖时,它将被翻译为糖果。


3
投票

一般响应JSON结构如下,所以要在行中使用它来提取它

source = intent.slots.source.resolutions.resolutionsPerAuthority [0] .values [0] .value.name;

"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"
            }
        }
    }
}

希望这会简单而有用。

© www.soinside.com 2019 - 2024. All rights reserved.