paper-matching / input_format.py
jskim's picture
gradio version update. adding more examples for the task. adding new fields for each paper.
fd61399
raw
history blame contribute delete
896 Bytes
from urllib.parse import urlparse
import requests
from semanticscholar import SemanticScholar
### Input Formatting
## Input formatting for the given author (reviewer)
# Extracting text from a link
def get_text_from_author_id(author_id, max_count=150):
if author_id is None:
raise ValueError('Input valid author ID')
aid = str(author_id)
if 'http' in aid: # handle semantic scholar url input
aid = aid.split('/')
aid = aid[-1]
# aid = aid[aid.index('author')+2]
url = "https://api.semanticscholar.org/graph/v1/author/%s?fields=url,name,paperCount,papers,papers.title,papers.abstract,papers.url,papers.year,papers.citationCount"%aid
r = requests.get(url)
if r.status_code == 404:
raise ValueError('Author link not found.')
data = r.json()
papers = data['papers'][:max_count]
name = data['name']
return name, papers