Watson Conversation - 从嵌套上下文中检索特定数据

Watson Conversation - Retrieving specific data from nested context

我希望互动看起来像这样:

现在,我已经对人口进行了硬编码,如下所示:

{
  "context": {
    "inputcountry": "<?@Country?>",
    "populations": {
      "USA": "300M",
      "Mexico": "100M",
      "Japan": "127M"
    }
  },
  "output": {
    "text": {
      "append": true,
      "values": [
        "The population of $inputcountry is approximately $populations.$inputcountry"
      ]
    }
  }
}

使用用户输入作为 identifier/lookup 来提供特定人口数量的语法是什么?

使用上面显示的 $populations.$inputcountry returns

{"USA": "300M","Mexico": "100M","Japan": "120M"}.Mexico

试试 <? $populations.get($inputcountry) ?> - 应该可以。

您可能需要为其编写多个对话..

 First dialogue triggering Condition: input.text.matches('USA') 
 Response: "The population of $input is approximately $populations.USA"


 Second dialogue triggering Condition: input.text.matches('Mexico')
 Response: "The population of $input is approximately $populations.Mexico"

Third dialogue triggering Condition: input.text.matches('Japan')
Response: "The population of $input is approximately $populations.Japan"

(任何对话节点都可以访问上下文变量)

另一种选择是将日本、美国、墨西哥创建为实体。