-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathresearch.qmd
More file actions
224 lines (185 loc) · 6.67 KB
/
research.qmd
File metadata and controls
224 lines (185 loc) · 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
---
title: "Research"
echo: false
jupyter: quarto-env
section-divs: false
format: html
---
```{python}
import yaml
import requests
from IPython.display import display, Markdown, HTML
import json
import os
from icon_utils import button
# Semantic Scholar Author ID
AUTHOR_ID = "90810256"
YAML_FILE = "papers.yaml"
def readable_list(_s):
if len(_s) < 3:
return ' and '.join(map(str, _s))
*a, b = _s
return f"{', '.join(map(str, a))}, and {b}"
def fetch_author_papers(author_id):
"""Fetch papers from Semantic Scholar API"""
base_url = "https://api.semanticscholar.org/graph/v1"
fields = "paperId,title,authors,year,venue,publicationDate,externalIds,openAccessPdf,url"
url = f"{base_url}/author/{author_id}/papers"
params = {'fields': fields, 'limit': 1000}
try:
response = requests.get(url, params=params)
response.raise_for_status()
return response.json()
except requests.RequestException as e:
print(f"Error fetching data from Semantic Scholar: {e}")
return None
def create_yaml_entry_from_ss_paper(paper):
"""Convert Semantic Scholar paper to YAML entry format"""
paper_id = paper.get('paperId')
title = paper.get('title', 'Untitled')
year = paper.get('year')
venue = paper.get('venue', '')
# Process authors
authors = []
for author in paper.get('authors', []):
author_name = author.get('name', '')
if 'Dimmery' in author_name:
authors.append("me")
else:
authors.append(author_name)
entry = {
'title': title,
'authors': authors,
'year': year,
'venue': venue if venue else None,
'visible': False, # Default to not visible
'ssid': paper_id,
}
# Add external links if available
external_ids = paper.get('externalIds', {})
if external_ids.get('DOI'):
entry['published_url'] = f"https://doi.org/{external_ids['DOI']}"
if external_ids.get('ArXiv'):
entry['preprint'] = f"https://arxiv.org/abs/{external_ids['ArXiv']}"
# Add open access PDF if available
open_access = paper.get('openAccessPdf')
if open_access and open_access.get('url'):
entry['pdf_url'] = open_access['url']
return entry
def sync_with_semantic_scholar():
"""Sync YAML file with new papers from Semantic Scholar"""
# print("Fetching papers from Semantic Scholar...")
# Load existing YAML data
if os.path.exists(YAML_FILE):
with open(YAML_FILE, 'r') as f:
yaml_data = yaml.safe_load(f) or {}
else:
yaml_data = {}
# Get existing SSIDs to avoid duplicates
existing_ssids = set()
for key, data in yaml_data.items():
if 'ssid' in data:
existing_ssids.add(data['ssid'])
# Fetch from Semantic Scholar
ss_papers = fetch_author_papers(AUTHOR_ID)
if not ss_papers or 'data' not in ss_papers:
# print("Failed to fetch papers from Semantic Scholar")
return yaml_data
new_papers_count = 0
for paper in ss_papers['data']:
paper_id = paper.get('paperId')
if paper_id and paper_id not in existing_ssids:
# Create a unique key for the new paper
title_key = paper.get('title', '').lower().replace(' ', '_').replace(',', '').replace(':', '')[:20]
year = paper.get('year', 'unknown')
key = f"{title_key}_{year}"
# Ensure unique key
counter = 1
original_key = key
while key in yaml_data:
key = f"{original_key}_{counter}"
counter += 1
yaml_data[key] = create_yaml_entry_from_ss_paper(paper)
new_papers_count += 1
if new_papers_count > 0:
# Write back to YAML file
with open(YAML_FILE, 'w') as f:
yaml.dump(yaml_data, f, default_flow_style=False, sort_keys=False)
# print(f"Added {new_papers_count} new papers to {YAML_FILE}")
else:
pass
# print("No new papers found")
return yaml_data
# Sync with Semantic Scholar to get any new papers
yaml_data = sync_with_semantic_scholar()
# Process papers for display (only visible ones)
pub_strs = {"pubs": {}, "wps": {}}
for key, data in yaml_data.items():
# Only show visible papers
if not data.get('visible', False):
continue
title_str = data["title"]
authors = data.get("authors", ["me"])
authors = [aut if aut != "me" else "<strong>Drew Dimmery</strong>" for aut in authors]
author_str = readable_list(authors)
year_str = str(data["year"])
buttons = []
# Preprint button
preprint = data.get("preprint")
if preprint:
buttons.append(button(preprint, "Preprint", "bi-file-earmark-pdf"))
# GitHub button
github = data.get("github")
if github:
buttons.append(button(github, "Github", "bi-github"))
# Data button
data_url = data.get("data")
if data_url:
buttons.append(button(data_url, "Data", "bi-database"))
# PDF button
pdf_url = data.get("pdf_url")
if pdf_url:
buttons.append(button(pdf_url, "PDF", "bi-file-earmark-pdf"))
# Published URL
pub_url = data.get("published_url")
venue = data.get("venue")
working_paper = pub_url is None
pub_str = f'{author_str}. ({year_str}) "{title_str}."'
if venue:
pub_str += f" <em>{venue}</em>"
if working_paper:
if year_str not in pub_strs["wps"]:
pub_strs["wps"][year_str] = []
pub_strs["wps"][year_str].append(
"<li class='list-group-item'>" + pub_str + "<br>" + " ".join(buttons) + "</li>"
)
else:
if year_str not in pub_strs["pubs"]:
pub_strs["pubs"][year_str] = []
buttons.append(button(pub_url, "Published", "ai-archive"))
pub_strs["pubs"][year_str].append(
"<li class='list-group-item'>" + pub_str + "<br>" + " ".join(buttons) + "</li>"
)
```
## Published
```{python}
#| label: "published-year"
#| id: "published-year"
#| output: asis
for year in sorted(pub_strs["pubs"].keys(), reverse=True):
display(Markdown(f"### {year}" + "{#" + f"published-{year}" + "}"))
display(HTML(
"<ul class='list-group list-group-flush'>" + '\n'.join(pub_strs["pubs"][year]) + "</ul>"
))
```
## Working Papers / Non-archival
```{python}
#| label: "not-published-year"
#| id: "not-published-year"
#| output: asis
for year in sorted(pub_strs["wps"].keys(), reverse=True):
display(Markdown(f"### {year}" + "{#" + f"not-published-{year}" + "}"))
display(HTML(
"<ul class='list-group list-group-flush'>" + '\n'.join(pub_strs["wps"][year]) + "</ul>"
))
```