Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IBM Watson Assistant:如何以XML语法显示/打印字典(python3)?_Xml_Ibm Cloud_Ibm Watson_Watson Assistant - Fatal编程技术网

IBM Watson Assistant:如何以XML语法显示/打印字典(python3)?

IBM Watson Assistant:如何以XML语法显示/打印字典(python3)?,xml,ibm-cloud,ibm-watson,watson-assistant,Xml,Ibm Cloud,Ibm Watson,Watson Assistant,我想在IBMWatson中将python字典的一些上下文显示为输出。 例如,如果我有一本这样的字典 {'author': 'Bloomberg News', 'title': 'India Crisis Worsens; N.Y. Deaths at 5-Month Low: Virus Update', 'description': 'India Crisis Worsens; N.Y. Deaths at 5-Month Low: Virus Update', 'url': 'http

我想在IBMWatson中将python字典的一些上下文显示为输出。 例如,如果我有一本这样的字典

{'author': 'Bloomberg News',
 'title': 'India Crisis Worsens; N.Y. Deaths at 5-Month Low: Virus Update',
 'description': 'India Crisis Worsens; N.Y. Deaths at 5-Month Low: Virus Update',
 'url': 'https://www.bloombergquint.com/business/n-y-deaths-at-5-month-low-india-crisis-deepens-virus-update',
 'source': 'Bloomberg | Latest And Live Business',
 'image': None,
 'category': 'business',
 'language': 'en',
 'country': 'us',
 'published_at': '2021-05-02T04:48:26+00:00'}
然后,要在IBM Watson Assistant中将标题打印为输出,我们需要这样写:

<?data['title']?>

[{'author': 'BQ Desk',
  'title': 'Coronavirus Updates: India Reports 3.9 Lakh New Covid Cases, 3,689 Deaths',
  'description': 'Coronavirus Updates: India Reports 3.9 Lakh New Covid Cases, 3,689 Deaths',
  'url': 'https://www.bloombergquint.com/coronavirus-outbreak/coronavirus-updates-india-reports-39-lakh-new-covid-cases-3689-deaths',
  'source': 'Bloomberg | Latest And Live Business',
  'image': None,
  'category': 'business',
  'language': 'en',
  'country': 'us',
  'published_at': '2021-05-02T05:15:34+00:00'},
 {'author': None,
  'title': 'Leasebak is geen heilige koe meer',
  'description': 'Managers met een leasebak in je arbeidsvoorwaarden, de vanzelfsprekendheid van de auto van de zaak gaat er vanaf. Als je nu solliciteert, zijn er steeds minder bedrijven die daar zomaar in willen meegaan. Door corona en thuiswerken nemen bedrijven hun mobiliteit nog eens extra onder de loep, zien leaseorganisaties en werkgeversorganisatie AWVN.',
  'url': 'https://www.telegraaf.nl/financieel/1632068442/leasebak-is-geen-heilige-koe-meer',
  'source': 'De Telegraaf - Financieel Overzicht',
  'image': 'https://www.telegraaf.nl/images/1200x630/filters:format(jpeg):quality(80)/cdn-kiosk-api.telegraaf.nl/a64d720a-a9c6-11eb-83a5-02d1dbdc35d1.jpg',
  'category': 'business',
  'language': 'nl',
  'country': 'nl',
  'published_at': '2021-05-02T05:00:00+00:00'},
 {'author': 'Bloomberg News',
  'title': 'India Crisis Worsens; N.Y. Deaths at 5-Month Low: Virus Update',
  'description': 'India Crisis Worsens; N.Y. Deaths at 5-Month Low: Virus Update',
  'url': 'https://www.bloombergquint.com/business/n-y-deaths-at-5-month-low-india-crisis-deepens-virus-update',
  'source': 'Bloomberg | Latest And Live Business',
  'image': None,
  'category': 'business',
  'language': 'en',
  'country': 'us',
  'published_at': '2021-05-02T04:48:26+00:00'},
 {'author': 'FE Online',
  'title': 'Coronavirus in India Live News: PM Modi to meet experts today to review oxygen & medicine availability; India reports 3.92 lakh Covid-19 cases',
  'description': 'Coronavirus Daily Cases and Deaths in India, Covid-19 India Lockdown, May 1 Phase 3 vaccine drive, Day 2 vaccination drive for 18+ years, CoWIN Covid-19 Vaccination Registration, May 2: Prime Minister Narendra Modi is expected to review the human resource situation, in relation to the Covid-19 pandemic, and ways to augment it.',
  'url': 'https://www.financialexpress.com/lifestyle/health/coronavirus-lockdown-in-india-coronavirus-cases-in-india-today-live-covid-19-cowin-vaccine-registration-vaccination-drive-rollout-coronavirus-daily-cases-and-deaths-in-india-covid-19-lockdown-in-del-2/2244047/',
  'source': 'The Financial Express',
  'image': 'https://images.financialexpress.com/2021/05/covid-second-wave.jpg',
  'category': 'business',
  'language': 'en',
  'country': 'us',
  'published_at': '2021-05-02T04:28:25+00:00'},
 {'author': 'Uppsala University',
  'title': 'Newly Discovered Immune Cell Function Vital to Healing May Lead to Treatments for Cancer and Cardiovascular Diseases',
  'description': 'Cardiovascular disease, the most common cause of death, is the result of oxygen deprivation as blood perfusion to affected tissue is prevented. To halt the...The post Newly Discovered Immune Cell Function Vital to Healing May Lead to Treatments for Cancer and Cardiovascular Diseases appeared first on SciTechDaily.',
  'url': 'https://scitechdaily.com/newly-discovered-immune-cell-function-vital-to-healing-may-lead-to-treatments-for-cancer-and-cardiovascular-diseases/',
  'source': 'Scitechdaily | Science Space And Technology News 2017',
  'image': None,
  'category': 'science',
  'language': 'en',
  'country': 'us',
  'published_at': '2021-05-01T22:40:45+00:00'}]

然后,如何用XML打印每篇文章的标题名(正如我上面提到的语法)


查看您的需求,您可能希望查看可应用于数据的方法列表,请参阅。使用这些方法,您可以将数组操作成所需的输出

或者,您可以调用一个外部RESTAPI来操作数据并返回所需的输出。此外部api可以是IBM云函数。


最后,也是最简单的,您可以拥有一个对话框节点,该节点具有多个响应条件,对应于应答数组的大小(python中的列表/目录)。但是,这种方法通常只适用于小的回答组,并且知道数组/列表/目录的最大大小。

我删除了Python标记。我假设这是在Watson Assistant中,没有使用Python SDK或Python客户端,对吗?
Desired Output:
Coronavirus Updates: India Reports 3.9 Lakh New Covid Cases, 3,689 Deaths
Leasebak is geen heilige koe meer
India Crisis Worsens; N.Y. Deaths at 5-Month Low: Virus Update
Coronavirus in India Live News: PM Modi to meet experts today to review oxygen & medicine availability; India reports 3.92 lakh Covid-19 cases
Newly Discovered Immune Cell Function Vital to Healing May Lead to Treatments for Cancer and Cardiovascular Diseases