Skip to content

Instantly share code, notes, and snippets.

@devStepsize
Last active May 5, 2016 18:12
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/7c9c82f8092c88bd5cc2e558d49ea856 to your computer and use it in GitHub Desktop.
Save devStepsize/7c9c82f8092c88bd5cc2e558d49ea856 to your computer and use it in GitHub Desktop.
Extract entities from a given webpage with the AlchemyAPI by giving it a URL
import requests
endpoint = "http://gateway-a.watsonplatform.net/calls/url/URLGetRankedNamedEntities"
parameters = {
'apikey': API_KEY,
'outputMode': 'json',
'url': 'https://www.reddit.com/'
}
r = requests.get(endpoint, params=parameters)
if r.status_code == 200:
resp = r.json()
# Print entities, type and relevance score.
# Entities are already ranked by relevance, high -> low
entities = [(e['text'], e['type'], e['relevance']) for e in resp.get('entities')]
# Print top 3 most relevant
print entities[:3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment