在沃森对话中如何提取输入文本中输入的多个值
In watson conversation how to extract multiple values entered in input text
我正在开发一个应用程序,根据用户的 "price range"..
在我的库存中显示产品
我需要知道如何提取输入文本中输入的值(价格)。
我尝试使用系统实体@sys-currency 和@sys-number 但我只能提取一个值(第一个值)..
示例:
用户要求"display products between 0 and 0"
如何提取要与单个产品价格进行比较的值并显示相关产品..
感谢建议..
如果您使用的是 nodejs,根据来自 IBM Developers 的简单对话示例,您可以执行如下操作:
节点:
访问此值的代码:
function updateMessage(input, data, req, res) {
console.log("Entties: "+JSON.stringify(data.entities));
//200 and 500 do something
if (data.entities[0].value == '200' && data.entities[1].value == '500') {
console.log("User choice value:" + data.entities)
// showProducts(data, req, res); do something inside this function
// or paste your code for do something here
}
调试:
Obs.: 如果用户只键入一个值 (@sys-currency),您将需要创建一个 if 条件,并获取该值以执行某些操作在您的应用程序中以我的示例为例:
data.entities //if have one value
data.entities[i] //Watson return some array if have more than 1 value
一个好主意是使用上下文变量并加入以获取所有值,例如:
{ "context": {
"result": "<? @sys-currency ?>"
}
},
如果您在上下文中传递所有有库存的商品,并且您希望输出像我们有 X、Y、Z 有库存,那么您可以在 Watson 中创建输出
<? context.results.join(', ') ?> //all values return
重要提示:您需要从 Watson Conversation 调用(conversation.message
) 用于访问所有值,例如实体、意图和上下文变量等。喜欢:
conversation.message(payload, function (err, data) {
console.log(data)
if (err) {
return res.status(err.code || 500).json(err);
}
}
在 watson 对话的节点中,您可以访问数组形式的实体。在你的情况下它将是:
Currency 1: <? entities['sys-currency'] != null && entities['sys-currency'].size()> 0 ? entities['sys-currency'][0].value : "---" ?>; Currency 2: <? entities['sys-currency'] != null && entities['sys-currency'].size()> 1 ? entities['sys-currency'][1].value : "---" ?>
您需要添加适当的空值检查并检查数组中的货币是否多于一个输入的货币
我正在开发一个应用程序,根据用户的 "price range"..
在我的库存中显示产品我需要知道如何提取输入文本中输入的值(价格)。
我尝试使用系统实体@sys-currency 和@sys-number 但我只能提取一个值(第一个值)..
示例:
用户要求"display products between 0 and 0"
如何提取要与单个产品价格进行比较的值并显示相关产品..
感谢建议..
如果您使用的是 nodejs,根据来自 IBM Developers 的简单对话示例,您可以执行如下操作:
节点:
访问此值的代码:
function updateMessage(input, data, req, res) {
console.log("Entties: "+JSON.stringify(data.entities));
//200 and 500 do something
if (data.entities[0].value == '200' && data.entities[1].value == '500') {
console.log("User choice value:" + data.entities)
// showProducts(data, req, res); do something inside this function
// or paste your code for do something here
}
调试:
Obs.: 如果用户只键入一个值 (@sys-currency),您将需要创建一个 if 条件,并获取该值以执行某些操作在您的应用程序中以我的示例为例:
data.entities //if have one value
data.entities[i] //Watson return some array if have more than 1 value
一个好主意是使用上下文变量并加入以获取所有值,例如:
{ "context": {
"result": "<? @sys-currency ?>"
}
},
如果您在上下文中传递所有有库存的商品,并且您希望输出像我们有 X、Y、Z 有库存,那么您可以在 Watson 中创建输出
<? context.results.join(', ') ?> //all values return
重要提示:您需要从 Watson Conversation 调用(conversation.message
) 用于访问所有值,例如实体、意图和上下文变量等。喜欢:
conversation.message(payload, function (err, data) {
console.log(data)
if (err) {
return res.status(err.code || 500).json(err);
}
}
在 watson 对话的节点中,您可以访问数组形式的实体。在你的情况下它将是:
Currency 1: <? entities['sys-currency'] != null && entities['sys-currency'].size()> 0 ? entities['sys-currency'][0].value : "---" ?>; Currency 2: <? entities['sys-currency'] != null && entities['sys-currency'].size()> 1 ? entities['sys-currency'][1].value : "---" ?>
您需要添加适当的空值检查并检查数组中的货币是否多于一个输入的货币