插槽同义词未按预期工作
Slot synonyms not working as expected
我正在尝试通过在 Alexa 技能中使用插槽同义词来处理实体解析。我从 Amazon 提供的问答游戏模板开始学习技能,其中包含城市名称、州缩写和首府的数据数组。我将其修改为使用 NFL 球队名称。在测验交互期间,例如,可能会询问用户 "What NFL football team plays in Philadelphia?"。用户可以回答 "Eagles" 或 "Philadelphia Eagles",这两者都应该可以接受以获得正确的分数。短语 "Philadelphia Eagles" 在我的 lambda 函数内的数据数组中定义。在交互模型中,在我的 AnswerIntent 中,我有一个定义为 TeamName 的插槽。我尝试在同义词中为 "Philadelphia Eagles" 和 "Eagles" 添加值。我使用 BIRDS 作为同义词 ID,使用 Eagles 作为值,使用 Philadelphia Eagles 作为同义词值。但是当我用 "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;
}
}
如果你想使用同义词,你必须使用 entity resolutions。那里有几个同义词的一个 ID,您可以检查。
因此,您的 compareSlots 函数应该如下所示:
[...]
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()) {
[...]
我正在尝试通过在 Alexa 技能中使用插槽同义词来处理实体解析。我从 Amazon 提供的问答游戏模板开始学习技能,其中包含城市名称、州缩写和首府的数据数组。我将其修改为使用 NFL 球队名称。在测验交互期间,例如,可能会询问用户 "What NFL football team plays in Philadelphia?"。用户可以回答 "Eagles" 或 "Philadelphia Eagles",这两者都应该可以接受以获得正确的分数。短语 "Philadelphia Eagles" 在我的 lambda 函数内的数据数组中定义。在交互模型中,在我的 AnswerIntent 中,我有一个定义为 TeamName 的插槽。我尝试在同义词中为 "Philadelphia Eagles" 和 "Eagles" 添加值。我使用 BIRDS 作为同义词 ID,使用 Eagles 作为值,使用 Philadelphia Eagles 作为同义词值。但是当我用 "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;
}
}
如果你想使用同义词,你必须使用 entity resolutions。那里有几个同义词的一个 ID,您可以检查。
因此,您的 compareSlots 函数应该如下所示:
[...]
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()) {
[...]