Last active
May 5, 2016 18:12
-
-
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
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
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