Watson Conversation - Retrieving specific data from nested context

陌路散爱 提交于 2019-12-12 21:24:00

问题


I'd like the interaction to look like this:

  • Bot: Name a country
  • User: Mexico
  • Bot: The population of Mexico is approximately 120M.

For now, I've got the populations hard-coded and looks like below:

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

What is the syntax to provide the specific population number using the user input as the identifier/lookup?

Using $populations.$inputcountry shown above returns

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

回答1:


Try <? $populations.get($inputcountry) ?> - that should do the trick.




回答2:


You might have to write multiple dialogues for it..

 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"

(Any dialog node can access context variables)

Another option would be to create Japan,USA,Mexico as entities.



来源:https://stackoverflow.com/questions/42779498/watson-conversation-retrieving-specific-data-from-nested-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!