-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubs.py
306 lines (266 loc) · 8.78 KB
/
pubs.py
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import sys
import re
from collections import defaultdict
import configargparse
from typing import Dict, List
UW_STUDENTS = [
"Xieyang Xu",
"Tapan Chugh",
"Xiangfeng Zhu",
"Weixin Deng",
"Anish Nyayachavadi",
"Shubham Tiwari",
"Wei Shen",
"Brody Frank",
"Natalie Neamtu",
"Yuyao Wang",
]
POSTDOCS = [
"Xiangyu Gao",
"Sam Kumar",
"Klaus-Tycho Forster",
"Monia Ghobadi",
"Hongqiang Liu",
]
MSR_STUDENTS = [
"Nick Giannarakis",
"Danyang Zhuo",
"Arpit Gupta",
"Aaron Gember-Jackson",
"Ryan Beckett",
"Seyed Fayaz",
"Raajay Vishwanathan",
"Xin Jin",
"Hongqiang Liu",
"Peng Sun",
"Ari Fogel",
"Rayman Preet Singh",
"Luis Pedrosa",
"Vijay Adhikari",
"Yingying Chen",
"Chun-Te Chu",
"Chi-Yao Hong",
"Jason Croft",
"Colin Dixon",
"Hossein Falaki",
"Radhika Niranjan Mysore",
"Patrick Verkaik",
"Aruna Balasubramanian",
"Lindsey Poole",
"Krishna Ramachandran",
]
def print_header():
print(
"""
<html>
<head>
<title>ratul's publications</title>
</head>
<body bgcolor="#ffffff">
"""
)
def print_footer():
print(
"""
</body>
</html>
"""
)
def print_by_topic(topic_order, topics, all_entries):
print("<ul>")
for topic in topic_order:
if re.search(r"selected|ignore", topic):
continue
print(f'<li><a href="#{topic}">{topics[topic]}</a>')
print("</ul>")
for topic in topic_order:
if re.search(r"selected|ignore", topic):
continue
print(f"<p><a name={topic}></a>\n<b>{topics[topic]}</b>")
print(
"""
<table style="width: 100%;" cellpadding="2" cellspacing="2">
<tr><td width=10px><td></tr>
"""
)
for entry in all_entries:
if re.search(topic, entry["topics"]):
if re.search(r"ignore", entry["topics"]):
continue
print_paper(entry)
print("</table>")
def print_by_time(all_entries):
last_printed_year = -1
for entry in all_entries:
year = entry["year"]
if year != last_printed_year:
print("</table>")
print(f"<p><b>{year}</b>")
print(
"""
<table style="width: 100%;" cellpadding="2" cellspacing="2">
<tr><td width=10px><td></tr>
"""
)
last_printed_year = year
if re.search(r"ignore", entry["topics"]):
continue
print_paper(entry)
def print_pubtype(all_entries: List[Dict[str, str]]) -> None:
pub_types = defaultdict(lambda: [])
for entry in all_entries:
pub_types[entry["pubtype"]].append(entry)
print(f"Found pubtypes: {pub_types.keys()}", file=sys.stderr)
for pub_type, entries in pub_types.items():
print(f"<p><b>{pub_type}</b><br>")
for entry in entries:
if re.search(r"ignore", entry["topics"]):
continue
print_paper_pubtype(pub_type, entry)
def print_paper_pubtype(pub_type: str, entry: Dict[str, str]) -> None:
print(f"printing {entry['paperKey']}", file=sys.stderr)
print("<p>")
if "impact" in entry:
print("<sup>*</sup>", end="")
authors = [author for author in entry["author"].split(" and ")]
for index, author in enumerate(authors):
if index == len(authors) - 1 and len(authors) != 1:
# last author?
print(f" and ", end="")
else:
print(f" ", end="")
print(f"{author}", end="")
# add a comma if we have more than two authors and this is not the last author
if index < len(author) - 1 and len(author) > 2:
print(",", end="")
if author in UW_STUDENTS or author in MSR_STUDENTS:
print("<sup>1</sup>", end="")
if author in POSTDOCS:
print("<sup>2</sup>", end="")
title = re.sub(r"(\{|\})", "", entry["title"])
print(f" ``{title}''", end="")
venue = (
entry.get("booktitle")
or entry.get("journal")
or entry.get("howpublished")
or "unknown"
)
print(f", <i>{venue}</i>", end="")
if re.search(r"article", entry["paperType"]):
print(f", {entry['volume']}({entry['number']})", end="")
if "pages" in entry:
print(f", pages {entry['pages']}", end="")
print(f", {entry['month']} {entry['year']}.", end="")
if "acceptancerate" in entry:
print(f" ({entry['acceptancerate']}% acceptance rate)", end="")
if "citations" in entry:
print(f" ({entry['citations']} citations)", end="")
if "note" in entry:
print(f" <b>({entry['note']})</b>")
def print_cv(topic_order, topics, all_entries):
for topic in topic_order:
if re.search(r"selected|ignore", topic):
continue
print(f"\\item {{\\bf {topics[topic]}}}")
print("\\begin{innerlist}")
for entry in all_entries:
if re.search(topic, entry["topics"]):
if re.search(r"ignore", entry["topics"]) or re.search(
r"misc", entry["paperType"]
):
continue
author = entry["author"].replace(" and ", ", ")
venue = (
entry.get("booktitle")
or entry.get("journal")
or entry.get("howpublished")
or "unknown"
)
title = re.sub(r"(\{|\})", "", entry["title"])
print("\\item")
if "impact" in entry:
print("\\hspace{-0.15in} * ")
print(f" {author},")
print(f" ``{title},''")
print(f" {{\\em {venue},}}")
if re.search(r"article", entry["paperType"]):
print(f" {entry['volume']}({entry['number']},")
print(f" {entry['month']} {entry['year']}.")
if "acceptancerate" in entry:
print(f" ({entry['acceptancerate']}\\% acceptance rate)")
if "note" in entry:
print(f" {{\\bf {entry['note']}}}")
print("\\end{innerlist}")
def print_paper(entry):
author = entry["author"].replace(" and ", ", ")
venue = (
entry.get("booktitle")
or entry.get("journal")
or entry.get("howpublished")
or "unknown"
)
title = re.sub(r"(\{|\})", "", entry["title"])
print(
f"""
<a href={entry['URL']}><b>{title}</b></a><br>
{author}<br>
{venue}, {entry['year']}<br>
"""
)
if "note" in entry:
print(f"<b>{entry['note']}</b><br>")
if "resource" in entry:
print(f"{entry['resource']}<br>")
print("<br>")
def main():
parser = configargparse.ArgParser(description="Process publication data.")
parser.add_argument("--verbose", action="store_true", help="debug mode [off]")
parser.add_argument(
"--mode", type=str, default="time", choices=["time", "topic", "cv", "pubtype"]
)
parser.add_argument("files", nargs="+", help="list of files")
args = parser.parse_args()
topic_order = []
topics = {}
all_entries = []
for file in args.files:
with open(file, "r") as f:
for line in f:
if re.match(r"^\@comment", line) or re.match(r"^\s*$", line):
# ignore comments and blank lines
continue
elif match := re.match(r"^([a-z]+)\s+:: (.+)$", line):
# topic lines at the top of the file
topic_key, topic = match.groups()
topics[topic_key] = topic
topic_order.append(topic_key)
elif match := re.match(r"^\@([a-z]+)\{(.+)\,", line):
# the first line of an entry
paper_type, paper_key = match.groups()
all_entries.append({"paperType": paper_type, "paperKey": paper_key})
elif match := re.match(r"\s+([a-zA-Z]+)=\{(.+)\}", line):
# following up lines of an entry
key, value = match.groups()
if key in all_entries[-1]:
raise ValueError(
f"duplicate {key=} in {all_entries[-1]['paperKey']}"
)
all_entries[-1][key] = value
if args.mode == "time":
print_header()
print_by_time(all_entries)
print_footer()
elif args.mode == "topic":
print_header()
print_by_topic(topic_order, topics, all_entries)
print_footer()
elif args.mode == "cv":
print_cv(topic_order, topics, all_entries)
elif args.mode == "pubtype":
print_header()
print_pubtype(all_entries)
print_footer()
else:
raise ValueError(f"unknown mode: {args.mode}")
if __name__ == "__main__":
main()