alchemy_language.entities 是否仍支持 outputMode

Is outputMode Still Supported In alchemy_language.entities

我有这个继承的代码,它在 Python 2.7 中成功 returns 导致 xml 然后由 ElementTree 解析。

result = alchemyObj.TextGetRankedNamedEntities(text)

root = ET.fromstring(result)

我正在将程序更新到 Python 3.5 并尝试这样做,这样我就不需要修改 xml 结果解析:

result = alchemy_language.entities(outputMode='xml', text='text', max_
items='10'),

root = ET.fromstring(result)

Per http://www.ibm.com/watson/developercloud/alchemy-language/api/v1/#entities outputMode 允许在 json 默认值和 xml 之间进行选择。但是,我收到此错误:

Traceback (most recent call last):
  File "bin/nerv35.py", line 93, in <module>
    main()
  File "bin/nerv35.py", line 55, in main
    result = alchemy_language.entities(outputMode='xml', text='text', max_items='10'),
TypeError: entities() got an unexpected keyword argument 'outputMode'

outputMode实际上还存在吗?如果是这样,实体参数有什么问题?

watson-developer-cloud 似乎没有此实体选项。允许的设置是:

html
text
url
disambiguate
linked_data
coreference
quotations
sentiment
show_source_text
max_items
language
model

您可以尝试使用 requests 直接访问 API。例如:

import requests

alchemyApiKey = 'YOUR_API_KEY'
url = 'https://gateway-a.watsonplatform.net/calls/text/TextGetRankedNamedEntities'

payload = { 'apikey': alchemyApiKey,
            'outputMode': 'xml',
            'text': 'This is an example text. IBM Corp'
           }

r = requests.post(url,payload)

print r.text

应该return这样:

<?xml version="1.0" encoding="UTF-8"?>
<results>
    <status>OK</status>
    <usage>By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html</usage>
    <url></url>
    <language>english</language>
    <entities>
        <entity>
            <type>Company</type>
            <relevance>0.961433</relevance>
            <count>1</count>
            <text>IBM Corp</text>
        </entity>
    </entities>
</results>