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
def enrich_keywords(all_articles, all_keywords, threshold=0.8, keyword_limit=10): | |
params = {} | |
limit = 0 | |
for key, value in all_articles.items(): | |
# Concatenate Title and Abstract and assign to dictionary item 'text' for API call. | |
params['text'] = value[0] + ". " + value[1] | |
content = aylien_api_connect(params=params) | |
# Accesses the new keywords from the newly generated keyword list from the API | |
for keys, values in content['concepts'].items(): | |
new_keyword = values['surfaceForms'][0]['string'] |
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
def aylien_api_connect(params, app_id, app_key, api_version): | |
# Define the API endpoint you would like to use - in this case "concepts". | |
endpoint = "concepts" | |
headers = { | |
'Accept': 'application/json', | |
'Content-type': 'application/x-www-form-urlencoded', | |
'X-AYLIEN-TextAPI-Application-ID': app_id, | |
'X-AYLIEN-TextAPI-Application-Key': app_key, | |
'User-Agent': "Aylien Text API Python " + api_version | |
} |
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
def genderize_api_connect(first_name): | |
url = 'https://api.genderize.io/?name={}'.format(first_name) | |
response = requests.get(url) | |
content = json.loads(response.content) | |
return content |
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
def aylien_api_connect(params, app_id, app_key, api_version): | |
# Define the API endpoint you would like to use - in this case "concepts". | |
endpoint = "concepts" | |
headers = { | |
'Accept': 'application/json', | |
'Content-type': 'application/x-www-form-urlencoded', | |
'X-AYLIEN-TextAPI-Application-ID': app_id, | |
'X-AYLIEN-TextAPI-Application-Key': app_key, | |
'User-Agent': "Aylien Text API Python " + api_version | |
} |
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
def genderize_api_connect(first_name): | |
url = 'https://api.genderize.io/?name={}'.format(first_name) | |
response = requests.get(url) | |
try: | |
assert response.status_code == 200 | |
content = json.loads(response.content) | |
except AssertionError: | |
self.logger.error("There was an error contacting the API service") | |
return content |