Is OutputMode supported in alchemy_language.entities

I have this legacy code that in Python 2.7 successfully returns results in xml, which are then processed by ElementTree.

result = alchemyObj.TextGetRankedNamedEntities(text)

root = ET.fromstring(result)

I am updating the program to Python 3.5 and trying to do this, so I do not need to modify the xml analysis of the results:

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 allows you to choose 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 really exist? If so, what is wrong with entity parameters?

+1
source share
1 answer

watson-developer-cloud, , . :

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

API , requests. :

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>
+1

Source: https://habr.com/ru/post/1652402/


All Articles