Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devStepsize/fbb9284fc5521c6135d19150c7637815 to your computer and use it in GitHub Desktop.
Save devStepsize/fbb9284fc5521c6135d19150c7637815 to your computer and use it in GitHub Desktop.
Get the topics for a given text using the Alchemy API
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