简体   繁体   English

IBM Watson对话:如何捕获和检索变量中的值列表

[英]IBM Watson Conversation: How to capture and retrieve a list of values in a variable

I have a dialog where users can enter one or more country names. 我有一个对话框,用户可以在其中输入一个或多个国家/地区名称。 How do I retrieve the values from the entity defined to store the responses. 如何从定义的实体中检索值以存储响应。

Example : Entity : Country 示例:实体:国家

Question : Where did you travel to? 问题:您去过哪里?
Answer : Africa, Thailand and China. 答:非洲,泰国和中国。

How can I capture these 3 values in a list entity? 如何在列表实体中捕获这3个值?

Henrik is right, just to add to that, What he said will return them in an array, if you do 亨里克(Henrik)是对的,仅此补充,如果您这样做,他说的内容将以数组形式返回

"countries": "<? entities['sys-location'] .toString() ?>"

you will get a comma separated list of the locations returned. 您将获得以逗号分隔的返回位置列表。

@sys-location entity in System Entities extracts location from the conversation. 系统实体中的@ sys-location实体从对话中提取位置。 (Note: Ensure that you have switched on that entity as shown below) (注意:确保已如下所示打开该实体)

在此处输入图片说明

You can now see that location has been extracted from conversation 现在,您可以看到该位置已从对话中提取

在此处输入图片说明

You can use the system entity for locations, @sys-location . 您可以将系统实体用于@sys-location You need to turn that capability on for your workspace. 您需要为工作空间启用该功能。 See the wizard for entity creations. 请参阅向导以创建实体。

In your dialog node where you want to capture the input in a list, you can assign those countries to a context variable . 在要在列表中捕获输入的对话框节点中,可以将这些国家/地区分配给上下文变量 Switch to the JSON editor to edit variables. 切换到JSON编辑器以编辑变量。 Then do something like: 然后执行以下操作:

"context": {
    "countries": "<? entities['sys-location'] ?>"
  },

See my collection of examples for context processing for something similar. 请参阅我的示例集合,以进行类似的上下文处理

Its Quite Simple. 非常简单。 Use 采用

"countries": "@sys-location.values"

It will list all @sys-location values in array form. 它将以数组形式列出所有@ sys-location值。

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

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