简体   繁体   English

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

[英]How to handle synonyms in intents in 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"
               }
            ]
         }

We need to handle the entity resolution in your backend code. 我们需要在后端代码中处理实体解析。 More can be referred here: https://developer.amazon.com/blogs/alexa/post/5de2b24d-d932-4c6f-950d-d09d8ffdf4d4/entity-resolution-and-slot-validation 更多内容可以在这里提到: https//developer.amazon.com/blogs/alexa/post/5de2b24d-d932-4c6f-950d-d09d8ffdf4d4/entity-resolution-and-slot-validation

In your code you can add, 在您的代码中,您可以添加,

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. 现在,当您的用户输入太妃糖时,它将被翻译为糖果。

The general response JSON structure would be as follows, so to extract it in a line use 一般响应JSON结构如下,所以要在行中使用它来提取它

source = intent.slots.source.resolutions.resolutionsPerAuthority[0].values[0].value.name; 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"
            }
        }
    }
}

Hope this would be simple and helpful. 希望这会简单而有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM