【发布时间】:2018-02-16 00:06:25
【问题描述】:
我正在尝试通过在 Alexa 技能中使用插槽同义词来处理实体解析。我从亚马逊提供的测验游戏模板开始我的技能,该模板包含城市名称、州缩写和大写字母的数据数组。我修改它以使用 NFL 球队名称。在测验交互期间,作为示例,用户可能会被问到“费城哪支 NFL 橄榄球队踢球?”。用户可以回答“Eagles”或“Philadelphia Eagles”,这两者都应该是可接受的以获得正确分数。短语“Philadelphia Eagles”是在我的 lambda 函数中的数据数组中定义的。在交互模型中,在我的 AnswerIntent 中,我有一个定义为 TeamName 的槽。我尝试在同义词中为“Philadelphia Eagles”和“Eagles”添加值。我使用 BIRDS 作为同义词 ID,Eagles 作为值,Philadelphia Eagles 作为同义词值。但是当我用“鹰”回答这个问题时,我得到了错误的答案。
我该如何纠正这个问题?
这是我在 Lambda 中的 AnswerIntent 函数:
"AnswerIntent": function() {
let response = "";
let speechOutput = "";
let item = this.attributes["quizitem"];
let property = this.attributes["quizproperty"];
let correct = compareSlots(this.event.request.intent.slots, item[property]);
if (correct)
{
response = getSpeechCon(true);
this.attributes["quizscore"]++;
}
else
{
response = getSpeechCon(false);
}
response += getAnswer(property, item);
if (this.attributes["counter"] < 10)
{
response += getCurrentScore(this.attributes["quizscore"], this.attributes["counter"]);
this.attributes["response"] = response;
this.emitWithState("AskQuestion");
}
else
{
response += getFinalScore(this.attributes["quizscore"], this.attributes["counter"]);
speechOutput = response + " " + EXIT_SKILL_MESSAGE;
this.response.speak(speechOutput);
this.emit(":responseReady");
}
},
这里是 compareSlot 函数:
function compareSlots(slots, value)
for (let slot in slots)
{
if (slots[slot].value != undefined)
{
if (slots[slot].value.toString().toLowerCase() == value.toString().toLowerCase())
{
return true;
}
}
}
return false;
更新:compareSlots 函数已修改为:
function compareSlots(slots, value)
{
let slotId = slot.value; // fallback if you don't have resolutions
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') {
if (resolution.values && resolution.values.length > 0) {
slotId = resolution.values[0].value.id;
}
}
if (slotId.toString().toLowerCase() == value.toString().toLowerCase()) {
return true;
}
}
【问题讨论】:
标签: aws-lambda alexa alexa-skills-kit