alchemy_language.entities是否仍支持outputMode [英] Is outputMode Still Supported In alchemy_language.entities
问题描述
我有这个继承的代码,该代码在Python 2.7中成功返回了xml中的结果,然后由ElementTree对其进行了解析。
I have this inherited code which in Python 2.7 successfully returns results in xml that are then parsed by ElementTree.
result = alchemyObj.TextGetRankedNamedEntities(text)
root = ET.fromstring(result)
我正在将程序更新为Python 3.5,并尝试执行此操作,以便无需修改结果的xml解析:
I am updating program to Python 3.5 and am attempting to do this so that I don't need to modify xml parsing of results:
result = alchemy_language.entities(outputMode='xml', text='text', max_
items='10'),
root = ET.fromstring(result)
每个 http://www.ibm.com/watson/developercloud/alchemy-language/api/v1/#entities outputMode允许在json默认值和xml。但是,我收到此错误:
Per http://www.ibm.com/watson/developercloud/alchemy-language/api/v1/#entities outputMode allows the choice between json default and xml. However, I get this error:
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'
输出模式实际上仍然存在吗?如果是这样,实体参数有什么问题?
Does outputMode actually still exist? If so, what is wrong with the entities parameters?
推荐答案
watson-developer-cloud
似乎没有用于实体的此选项。允许的设置为:
The watson-developer-cloud
does not appear to have this option for Entities. The settings allowed are:
html
text
url
disambiguate
linked_data
coreference
quotations
sentiment
show_source_text
max_items
language
model
您可以尝试使用请求
直接访问API。例如:
You can try accessing the API directly by using requests
. For example:
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
应返回以下内容:
<?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>
这篇关于alchemy_language.entities是否仍支持outputMode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!