Created
May 6, 2016 23:47
-
-
Save devStepsize/fbb9284fc5521c6135d19150c7637815 to your computer and use it in GitHub Desktop.
Get the topics for a given text using the Alchemy API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
endpoint = "http://gateway-a.watsonplatform.net/calls/text/TextGetRankedTaxonomy" | |
def get_topics(text): | |
data = { | |
'apikey': API_KEY, | |
'outputMode': 'json', | |
'text': text | |
} | |
headers = {'content-type': 'application/x-www-form-urlencoded'} | |
r = requests.post(endpoint, data=data, headers=headers) | |
if r.status_code == 200: | |
resp = r.json() | |
print [(t['label'], t['score']) for t in resp['taxonomy']] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment