Skip to content

Instantly share code, notes, and snippets.

@Guitaricet
Created July 16, 2019 12:27
Show Gist options
  • Save Guitaricet/8fd2a443352866e5854e5aedb9dbafe6 to your computer and use it in GitHub Desktop.
Save Guitaricet/8fd2a443352866e5854e5aedb9dbafe6 to your computer and use it in GitHub Desktop.
Get intersected citations
# Get papers that cite all papers from paper_ids
# more on api: https://api.semanticscholar.org/
import requests
from pprint import pprint
paper_ids = ['be69b703f91ab5ff962cd2b7e120eac8e1d3ca3b', '0b0cf7e00e7532e38238a9164f0a8db2574be2ea']
if __name__ == "__main__":
paper_jsons = []
citations = []
citation_ids = []
common_citations = []
for paper_id in paper_ids:
paper_json = requests.get(f'http://api.semanticscholar.org/v1/paper/{paper_id}').json()
paper_jsons.append(paper_json)
citations = paper_json['citations'] # any paper contain all common citations
citation_ids.append(c['paperId'] for c in paper_json['citations'])
common_citations_ids = set(citation_ids[0])
for paper_citation_ids in citation_ids[1:]:
common_citations_ids = common_citations_ids.intersection(set(paper_citation_ids))
print('Common citations:')
for citation in citations:
if citation['paperId'] in common_citations_ids:
# pprint(citation)
print('\t', citation['title'])
print('\t', citation['url'])
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment